Nathan Kurz wrote:

Hello --

I'm trying to track down a segfault that happens when I'm using
DBD::SQLite for Perl, and I'm confused by the documentation for
sqlite3_column_decltype().  I think I understand what it does, but
I think there are some typos that make me uncertain:

http://sqlite.org/capi3ref.html#sqlite3_column_decltype

The first argument is a prepared SQL statement. If this statement is
a SELECT statement, the Nth column of the returned result set of the
SELECT is a table column then the declared type of the table column
is returned. If the Nth column of the result set is not at table
column, then a NULL pointer is returned. The returned string is UTF-8
encoded for sqlite3_column_decltype() and UTF-16 encoded for
sqlite3_column_decltype16(). For example, in the database schema:

    CREATE TABLE t1(c1 INTEGER);
And the following statement compiled:

    SELECT c1 + 1, 0 FROM t1;
 Then this routine would return the string "INTEGER" for the second
 result column (i==1), and a NULL pointer for the first result column
 (i==0).

Is the first sentence supposed to be "If this statement is a SELECT
statement [and if] the Nth column..."?  And the next sentence should
be "is not [a] table column"?  And is the final paragraph correct, or
are the numbers reversed for which is NULL and which is "INTEGER"?
I think what's happening with the Perl interface is that
sqlite3_column_decltype() returns NULL if the table is created without
an explicit type, instead of the "" or "TEXT" that I would have
expected.  Is this correct?  Or should it return something else?

Thanks!

Nathan Kurz
[EMAIL PROTECTED]

Nathan,

I believe you are correct about the two typos, but I think the final paragraph is correct. I think the example select statement is wrong. It should read:

   SELECT c1+1, c1 FROM t1;

I have replace the zero with c1. Now the final paragraph makes sense. The first result column is the result of an expression, not a table column, so it returns a NULL pointer for the declared type string. The second result is from column c1 and the function returns a pointer to a string containing its declared type, "INTEGER".

As far as your Perl interface is concerned, if you didn't explicitly give the column a type, there is no declared type for it to return, so it should return an empty string. It shouldn't return a NULL pointer, that means the result is not taken directly from a table column.

HTH
Dennis Cote


Reply via email to