Re: [sqlite] how to get the meta type of a column

2010-02-04 Thread gujx

>If all you have is a void*, you're going to have a very hard time calling
any sqlite3_bind_*() function. 
yes, I just have all values with the type void*, so I can not choose which
sqlite3_bind_*() functions to use.





Jay A. Kreibich-2 wrote:
> 
> On Thu, Feb 04, 2010 at 06:41:46PM -0800, gujx scratched on the wall:
>> 
>> Maybe I didn't express the problem clearly.
>> > e.g. if you have a text value, you use _text(), if you have an int, you
>> > use _int()
> 
>> I just don't know what type I have,
> 
>   If all you have is a void*, you're going to have a very hard time
>   calling any sqlite3_bind_*() function.  I sure hope you know what YOU
>   have, you're just not sure about the place you want to stick it.
> 
>> so I want to get the meta type of the column somebody defined.
> 
>   One more time: columns don't have types.  There is no way to get the
>   affinity (that I'm aware of) other than replicating code internal to
>   SQLite.  Asking again won't change this.
> 
>> e.g. I'd like to use a bind routine to bind a variable t to a "?", but I
>> don't konw this t is a string or a number or it is a object,
> 
>   It doesn't matter.
> 
>> so I want to
>> know that the table is defined like "id(varchar)" ,then I will use
>> sqlite3_bind_text; or it is defined like "id(integer)", then I will
>> choose
>> sqlite3_bind_int.
> 
>   I understand that, but you need to put something in the third
>   parameter.  If you're going to call sqlite3_bind_text(), you need a
>   const char * for the third parameter.  If you're going to call 
>   sqlite3_bind_int(), you need an int for the third parameter.  What
>   you have, in your C code, will best dictate what bind function to
>   use.  SQLite will then do any conversions required, given the column
>   affinity, and it is generally going to do a better and smarter job
>   than your code can because it has more information about what is
>   going on.
> 
>> >  http://sqlite.org/datatype3.html
>> >  
>> >   Read this whole page.  Several times.  Make sure you understand it in
>> >   great detail.
> 
>-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
> 
> 

-- 
View this message in context: 
http://old.nabble.com/how-to-get-the-meta-type-of-a-column-tp27451326p27463630.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] how to get the meta type of a column

2010-02-04 Thread gujx

Maybe I didn't express the problem clearly.
> e.g. if you have a text value, you use _text(), if you have an int, you
> use _int()
I just don't know what type I have, so I want to get the meta type of the
column somebody defined.
e.g. I'd like to use a bind routine to bind a variable t to a "?", but I
don't konw this t is a string or a number or it is a object, so I want to
know that the table is defined like "id(varchar)" ,then I will use
sqlite3_bind_text; or it is defined like "id(integer)", then I will choose
sqlite3_bind_int.


Jay A. Kreibich-2 wrote:
> 
> On Thu, Feb 04, 2010 at 03:59:14PM +0800, gujx scratched on the wall:
>> There is a table like this:
> 
> 
>> Is there any way to resolve this?
> 
>   First off, you need to understand that columns do not have "types",
>   they have affinities.
> 
>  http://sqlite.org/datatype3.html
>  
>   Read this whole page.  Several times.  Make sure you understand it in
>   great detail.
> 
> 
> 
>   Second, you can put any type into (almost) any column, so it doesn't
>   matter.  If the affinity is setup right, SQLite will usually do the
>   right thing.  For example, if you have a column with numeric affinity
>   and you insert the text value '12', it will converted to an integer
>   before it is stored.
> 
>   Which bind function you use is usually dictated by what you have
>   (e.g. if you have a text value, you use _text(), if you have an int,
>   you use _int()), rather than the column you are placing it in. 
>   SQLite will try its best to convert what you've given it into a
>   format that makes sense for the column, but if it can't, it will store
>   it in whatever format you sent.  Which is more or less exactly the
>   position you'd be in if you wanted to do the conversion "by-hand."
> 
>-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
> 
> 

-- 
View this message in context: 
http://old.nabble.com/how-to-get-the-meta-type-of-a-column-tp27451326p27462879.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] how to get the meta type of a column

2010-02-04 Thread gujx
There is a table like this:


id(varchar)

name(text)

age(integer)

ss(text)

Its name is “test_for_cpp”, now I get the pointer of sqlite successfully. 

 

There are codes below:

 

sqlite3_stmt *ppStmt;

const char *pzTail; 

int nVal = sqlite3_prepare_v2(

   conn,   

   "INSERT INTO [test_for_cpp] ([id], [name], [age], [ss]) VALUES (?, ?,
?, ’exa’) ; ", 

   -1,

   ,  

   

);

 

now, I should use routines such as
 sqlite3_bind_text to bind data
with the “?”, but I don’t know the exact meta type of the column. 

I don’t know that the meta type of the column id is “integer”, and I
don’t know the meta type of the column name is “text”.…… So, I can’t
choose the exact bind routine.

Is there any way to resolve this?

 

 

 

Gu Jinxiang

 

以上、よろしくお��いします。

 

-- 

 

 

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] how to get the type of a parameter

2010-01-27 Thread gujx
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:

 

sqlite3 *conn;

if (SQLITE_OK != sqlite3_open("testBind.db", ))

{

   printf("can't open the database.");

   return ;

}

 

if(SQLITE_OK != sqlite3_exec(conn, "create table  test_for_cpp(id
integer,name text,age integer)", 0, 0, 0))

{

   return ;

}

 

   sqlite3_stmt *ppStmt;

const char *pzTail; 

int nVal =sqlite3_prepare_v2(

   conn,   

   "INSERT INTO [test_for_cpp] ([id], [age], [name]) VALUES (?, ?,
'xiaowang') ; ",

   -1,

   ,  

   

);

 

 

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.

 

 

Gu Jinxiang

 

以上、よろしくお��いします。

 

 

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] how to get the type of a parameter

2010-01-27 Thread gujx
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:

 

sqlite3 *conn;

if (SQLITE_OK != sqlite3_open("testBind.db", ))

{

   printf("can't open the database.");

   return ;

}

 

if(SQLITE_OK != sqlite3_exec(conn, "create table  test_for_cpp(id
integer,name text,age integer)", 0, 0, 0))

{

   return ;

}

 

   sqlite3_stmt *ppStmt;

const char *pzTail; 

int nVal =sqlite3_prepare_v2(

   conn,   

   "INSERT INTO [test_for_cpp] ([id], [age], [name]) VALUES (?, ?,
'xiaowang') ; ",

   -1,

   ,  

   

);

 

 

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.

 

Gu Jinxiang

 

以上、よろしくお��いします。

 

 

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] size control of sqlite database

2010-01-14 Thread gujx
Hi, I’d like to ask some question about the interface of the sqlite
resource.

Whether there is some interface to control the size of a database, for
example, if I want to create a database with 5M initialized, how can I do
that? And when I make change to a database, for example, insert a row to a
table, then can I get the size of the database now?

 

Looking forward to your answer.

 

 

Gu Jinxiang

 

以上、よろしくお��いします。

 

-- 

 

A new email address of FJWAN is launched from Apr.1 2007. 
The updated address is: g...@cn.fujitsu.com 

Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) 8/F., Civil Defense
Building, No.189 Guangzhou Road, Nanjing, 210029, China
TEL:+86+25-86630566-619
COINS:79955-619 
FAX:+86+25-83317685
email:g...@cn.fujitsu.com 
-- 
This communication is for use by the intended recipient(s) only and may
contain information that is privileged, confidential and exempt from
disclosure under applicable law. If you are not an intended 
recipient of this communication, you are hereby notified that any
dissemination, distribution or copying hereof is strictly prohibited. If you
have received this communication in error, please notify me by 
reply e-mail, permanently delete this communication from your system, and
destroy any hard copies you may have printed. 

 

 

 

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users