On Mon, Oct 26, 2009 at 05:28:50PM -0400, Rob Sciuk scratched on the wall:
> 
> I've just compiled the latest (3.6.19) with the
> 
> -DSQLITE_ENABLE_COLUMN_METADATA flag set.  The problem I'm seeing is that 
> when I use an aggregate function in a select, the table name is not being 
> returned from an sqlite3_column_table_name() is not returning the 
> tablename as expected from a prepared statement, whereas if I actually 
> request data from the table, it works fine:
> 
> eg:
> If I prepare the statement "select * from q_user", q_user is returned as 
> expected from sqlite3_column_table_name().
> 
> If I prepare the statement "select count(*) from q_user", 
> sqlite3_column_table_name() returns NULL.
> 
> This is somewhat disconcerting, and seems repeatable.  Are aggregate 
> functions handled differently than tuple data?

  The documentation on this is fairly clear:

      http://sqlite.org/c3ref/column_database_name.html

      If the Nth column returned by the statement is an expression or
      subquery and is not a column value, then all of these functions
      return NULL. These routine might also return NULL if a memory
      allocation error occurs. Otherwise, they return the name of the
      attached database, table and column that query result column was
      extracted from.

  Basically, in order for these functions to work, the returned column
  needs to be a raw, unaltered, column directly from a specific table.
  Any kind of expression (including aggregate functions) means the
  data values in that result did not come directly from a specific
  table column, and therefore these functions return NULL.

  If you need a more general way to get the name of any column in any
  query, you most likely want sqlite3_column_name().

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to