On Sat, Oct 20, 2012 at 11:11 AM, hakan <hexi...@users.sourceforge.net>wrote:


> Can a oosqlite ~step statement return the result as an
> OO_ARRAY_OF_DIRECTORIES or OO_STEM_OF_STEMS or is it only possible to get
> result as OO_ARRAY_OF_ARRAYS ?
> I have tried .oosqlite~OO_ARRAY_OF_DIRECTORIES, but still get the result
> as OO_ARRAY_OF_ARRAYS
> With ~exec it works OK
>

Hi,

The step method of the ooSQLiteStmt class returns an ooSQLite return code
constant, not a result set.  (I just read Staffan's reply and he is
essentially correct.)

The 3 most common return codes would be: BUSY, DONE, or ROW.  It is
possible to get some other error codes.

If the execution of the SQL of the statement returns data, the the return
of step() will be ROW.  Each return of ROW means that data for one row from
executing the SQL is ready.  DONE means that the execution of the SQL is
over and no data is now available..  BUSY means the database is currently
locked for some reason.

So if your SQL was something like:  SELECT * from TBL1  you would normally
use step() in a loop and extract each row.  Something similar to this:

  sql = "SELECT * FROM TBL1;"
  stmt = .ooSQLiteStmt~new(dbConn, sql)

  -- check for errors normally
  -- The below builds up a result set.
  count = 0
  -- We know there are at least 20,000 rows
  records = .array~new(20000)
  do while stmt~step == stmt~ROW
    count += 1
    record = .array~new(cols)

    do i = 1 to cols
      record[i] = stmt~columnText(i)
    end

    records[count] = record
  end

As Staffan said, or implied, each time you have a row ready, you use the
other methods of the ooSQLiteStmt class to extract your data.

The exec() method is perhaps more convenient, stepping through the results
yourself involves more coding, but gives you far more control.  The above
is not a good example of why you might prefer to use a ooSQLiteStmt object
rather than use exec(), it was just a quick way to show you how step()
works.

Sorry the doc is so skimpy for the ooSQLiteStmt class, but I've actually
got everything doc'd up to that class.  So it is next on the list.

Since I know you have downloaded the source code, you can do what Staffan
is doing and look at the method implementation code for some doc help.  For
instance, for columnText(), I have in ooSQLite.cpp:

/** ooSQLiteStmt::columnText()
 *
 *
 *  @param col  [required]  The column in the result row to get the text
for.
 *                          Although SQLite uses 0-based column numbers, the
 *                          Rexx programmer should use 1-based numbers as is
 *                          normal for Rexx.
 *
 *
 */
RexxMethod2(RexxObjectPtr, oosqlstmt_columnText, int32_t, col, CSELF,
pCSelf)
{
    pCooSQLiteStmt pCstmt = requiredStmt(context, pCSelf);
    if ( pCstmt == NULL )
    {
        return context->WholeNumber(SQLITE_MISUSE);
    }
    col--;
    return context->String(safeColumnText(pCstmt->stmt, col));
}

which is probably enough to give you the idea to code this:

    do i = 1 to cols
      record[i] = stmt~columnText(i)
    end

Another method implementation:

RexxMethod2(int, oosqlstmt_columnType, int32_t, col, CSELF, pCSelf)
{
    pCooSQLiteStmt pCstmt = requiredStmt(context, pCSelf);
    if ( pCstmt == NULL )
    {
        return SQLITE_MISUSE;
    }
    col--;
    return sqlite3_column_type(pCstmt->stmt, col);
}

Should be enough so that you can see that the columnType() method of the
ooSQLiteStmt class behaves exactly the same as the sqlite3_column_type()
API.  You then could go to:

http://www.sqlite.org/c3ref/funclist.html

and follow the link: sqlite3_column_type to:

http://www.sqlite.org/c3ref/column_blob.html

This then gives you *all* the information I know about the columnType()
method.

Not an ideal process for learning ooSQLite I admit.  But, I'm slowly
working on the doc, using just that process.  In some cases there will be
ooSQLite specific details that need to be added for someone to really
understand a method and its use.

All of the ooSQLiteStmt method implementations are grouped together.  Many
of the methods are doc'd in the comment header for each implementation.

In some cases I have implementation details in the C++ code comments, that
you would be wise to ignore.  Implementation is subject to change.  But,
it's open source so that kind of implementation detail is always available.

--
Mark Miesfeld
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to