dbBulkCommand()

Summarizes the ADO functions dbStartCommand() (prepares a data manipulation command), dbExecuteCommand() (executes a data manipulation command) and dbFinishCommand() (closes a data manipulation command).

Synopsis

int dbBulkCommand( dbConnection connection, string cmdStr [, dym_dyn_anytype paramValues]);

Parameters

Parameter Meaning
connection Connection reference supplied by dbOpenConnection().
cmdStr Data manipulation command (on behalf of SQL string).
paramValues The parameter is used to attach a list of "n" SQL parameter with "m" additional parameters for each SQL statement.

Return Value

The return value is an error code. 0 denotes successful execution of the operation. With other values detailed error information can be retrieved using dbGetError().

Errors

If an invalid connection or incorrect command (also syntax error) is transferred, an error is returned.

Description

Summarizes the ADO functions dbStartCommand() (prepares a data manipulation command), dbExecuteCommand() (executes a data manipulation command) and dbFinishCommand() (closes a data manipulation command).

Example

#uses "CtrlADO"
main()
{
  DebugN("STARTING");
  dbConnection conn;
  int ret =
  dbOpenConnection("driver=QMYSQL;server=localhost;uid=root;pwd=123456;
  database=test;port=3306;", conn); // opens the connection
  if ( ret != 0 )
  {
    DebugN("open failed");
    return;
  }
  DebugN("bulk", dbBulkCommand(conn, makeDynString("INSERT INTO
  text (text, num) VALUES ('abc', 1)", "INSERT INTO text (text,
  num) VALUES ('def', 2)")));
  // preparing, executing and closing data manipulation
  commands
  showError(conn);
  // test NULL values
  const string TEXT = "DDD";
  dbCommand command;
  ret = dbStartCommand(conn, "INSERT INTO text (text) VALUES ('" +
  TEXT + "')", command);
  if ( ret != 0 )
  return;
  ret = dbExecuteCommand(command);
  if ( ret != 0 )
  return;
  dbFinishCommand(command);
  // read back
  dbRecordset rec;
  ret = dbOpenRecordset(conn, "SELECT * FROM text", rec);
  if ( ret != 0 )
  {
    DebugN("open recordest failed");
    showError(conn);
    return;
  }
  dyn_dyn_anytype tab;
  dyn_string columns;
  mixed a;
  dyn_anytype da;
  while ( !dbEOF(rec) )
  {
    ret = dbGetRecord(rec, da);
    DebugN(ret, da);
    dbMoveNext(rec);
  }
  DebugN("closing", dbCloseConnection(conn));
}
void showError(dbConnection conn)
{
  int errCnt, errNo, errNative;
  string errDescr, errSql;
  int rc;
  errCnt = 1;
  rc = 0;
  while (errCnt > 0 && ! rc)
  {
    rc = dbGetError (conn, errCnt, errNo, errNative, errDescr,
    errSql);
    if (!rc)
    {
      DebugN("Errornumber : ", errNo);
      DebugN("BaseError : ", errNative);
      DebugN("Description : ", errDescr);
      DebugN("SQL-errortext: ", errSql);
    }
    else
    DebugN("dbGetError failed, rc = ", rc2);
    errCnt--;
  }
}

Assignment

ADO and Qt, Database functions

Availability

CTRL