Hey guys.

I'm using an SQLite implementation that someone else made for my 
high-level language of choice.

While looking through the imp, I've just found this function, which is 
used as the callback argument to sqlite3_exec.  Does this look like an 
ok useage?  It seems to me like this might be doing a lot of work for 
some data I may never use.

Any help much appreciated,
Thanks,
Ian

int Callback(void *pArg, int argc, char **argv, char **columnNames)
{
    // basically this callback is called for each row in the SQL query 
result.
    // for each row, argc indicates how many columns are returned.
    // columnNames[i] is the name of the column
    // argv[i] is the value of the column

    sqlite_resultrow* pRow;
    sqlite_resultset* pResultSet;
    char* name;
    char* value;
    int i;

    if (argc == 0)
       return 0;

    pResultSet = (sqlite_resultset*)pArg;
    if (!pResultSet)
       return -1;

    // create a new result row
    pRow = new sqlite_resultrow;
    pResultSet->iNumCols = argc;
    // loop through all the columns and stuff them into our row
    for (i = 0; i < argc; i++)
    {
       // DBEUG CODE
//      Con::printf("%s = %s\n", columnNames[i], argv[i] ? argv[i] : 
"NULL");
       name = new char[dStrlen(columnNames[i]) + 1];
       dStrcpy(name, columnNames[i]);
       pRow->vColumnNames.push_back(name);
       if (argv[i])
       {
          value = new char[dStrlen(argv[i]) + 1];
          dStrcpy(value, argv[i]);
          pRow->vColumnValues.push_back(value);
       }
       else
       {
          value = new char[10];
          dStrcpy(value, "NULL");
          pRow->vColumnValues.push_back(value);
       }
    }
    pResultSet->iNumRows++;
    pResultSet->vRows.push_back(pRow);

    // return 0 or else the sqlexec will be aborted.
    return 0;
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to