On Wed, Jan 27, 2010 at 01:43:36PM +0000, Simon Davies scratched on the wall:
> 2010/1/27 gujx <g...@cn.fujitsu.com>:
> > Hi, I had a question puzzled me. How can I get the type of a parameter in a
> > prepared SQL.
> >
> > For example, the code is:
> .
> .
> .
> >
> > ? ? ? "INSERT INTO [test_for_cpp] ([id], [age], [name]) VALUES (?, ?,
> > 'xiaowang') ; ",
> > ? ? ? -1,
> > ? ? ? &ppStmt,
> > ? ? ? &pzTail
> > ? ?);
> >
> > How can I get the type of the specific column that a ??? referenced to?
> > For example, I want to get the type (here is integer) of the first column
> > that the first ??? referenced to.

  Columns don't have types in SQLite, they have affinities.  They're
  not the same thing: http://www.sqlite.org/datatype3.html

> pragma table_info, see http://www.sqlite.org/pragma.html#pragma_table_info

  Yes, but that will return the actual defined type, not the column
  affinity. For example, if a column is defined "name varchar", then
  table_info will return "varchar", not "text."

  As far as I know, there is no way to extract the affinity of a
  column, other than trying to use the same algorithm SQLite uses.

  In short, the person that writes the query needs to know the expected
  type, just like every other database engine.  The main difference is
  that SQLite will happily accept any type you want, which can be good
  or bad, depending on what you're trying to do.  Adding a CHECK typeof()
  constraint is easy enough for those situations where you need a
  specific type.

   -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