Re: [sqlite] first few characters of varchar() corrupted when SELECTing from a C++ program?

2009-06-30 Thread freshie2004-sqlite
(embarrassed)

printf("testValue=(%s)\n", testValue);





From: John Machin <sjmac...@lexicon.net>
To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
Sent: Tuesday, 30 June, 2009 4:51:09 PM
Subject: Re: [sqlite] first few characters of varchar() corrupted when 
SELECTing from a C++ program?

On 30/06/2009 2:56 PM, freshie2004-sql...@yahoo.com.au wrote:

> printf("testValue=(%s)\n");

I've always been afraid to use those new-fangled mind-reading C 
compilers lest they were easily shocked ;-)

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



  

Access Yahoo!7 Mail on your mobile. Anytime. Anywhere.
Show me how: http://au.mobile.yahoo.com/mail
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] first few characters of varchar() corrupted when SELECTing from a C++ program?

2009-06-30 Thread John Machin
On 30/06/2009 2:56 PM, freshie2004-sql...@yahoo.com.au wrote:

> printf("testValue=(%s)\n");

I've always been afraid to use those new-fangled mind-reading C 
compilers lest they were easily shocked ;-)

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


Re: [sqlite] first few characters of varchar() corrupted when SELECTing from a C++ program?

2009-06-29 Thread freshie2004-sqlite
(Replying to pierr as I joined the list after uralmazamog sent original email)


uralmazamog,

The code is incomplete. You are not showing us how you are determining what 
testValue points to.

What is returned if you use the following?

sqlite3_open_v2( "testdat", sqlDB, SQLITE_OPEN_READWRITE |
SQLITE_OPEN_CREATE, NULL );
sqlite3_prepare_v2( sqlDB, "SELECT b FROM whee WHERE a='bing';", 
-1,sqlStat, NULL );
sqlite3_step( sqlStat );
const unsigned char *testValue = sqlite3_column_text( sqlStat, 0 );
printf("testValue=(%s)\n");

Cheers!






From: pierr <pierr.c...@gmail.com>
To: sqlite-users@sqlite.org
Sent: Tuesday, 30 June, 2009 2:42:16 PM
Subject: Re: [sqlite] first few characters of varchar() corrupted when 
SELECTing from a C++ program?




uralmazamog wrote:
> 
> Greetings,
> 
> maybe it's just me being stupid, I'll best jump right to the code:
> 
> sqlite3_open_v2( "testdat", sqlDB, SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE, NULL );
> sqlite3_prepare_v2( sqlDB, "SELECT b FROM whee WHERE a='bing';", -1,
> sqlStat, NULL );
> sqlite3_step( sqlStat );
> const unsigned char *testValue = sqlite3_column_text( sqlStat, 0 );
> 
> both a and b are varchar(20)s
> 
> calling the query from the command-line tool returns the proper result
> "bang", however, running this code the value testValue shows up as ""
> for longer strings only the first four characters are corrupted, and the
> rest reads okay, what am I doing wrong?
> 
> 
Try this:
char testValue[20];
memcpy(testValue,sqlite3_column_text(sqlStat,0),sqlite3_column_bytes(sqlStat,0));


-- 
View this message in context: 
http://www.nabble.com/first-few-characters-of-varchar%28%29-corrupted-when-SELECTing-from-a-C%2B%2B-program--tp24237176p24266020.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



  

Access Yahoo!7 Mail on your mobile. Anytime. Anywhere.
Show me how: http://au.mobile.yahoo.com/mail
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] first few characters of varchar() corrupted when SELECTing from a C++ program?

2009-06-29 Thread pierr



uralmazamog wrote:
> 
> Greetings,
> 
> maybe it's just me being stupid, I'll best jump right to the code:
> 
> sqlite3_open_v2( "testdat", sqlDB, SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE, NULL );
> sqlite3_prepare_v2( sqlDB, "SELECT b FROM whee WHERE a='bing';", -1,
> sqlStat, NULL );
> sqlite3_step( sqlStat );
> const unsigned char *testValue = sqlite3_column_text( sqlStat, 0 );
> 
> both a and b are varchar(20)s
> 
> calling the query from the command-line tool returns the proper result
> "bang", however, running this code the value testValue shows up as ""
> for longer strings only the first four characters are corrupted, and the
> rest reads okay, what am I doing wrong?
> 
> 
Try this:
char testValue[20];
memcpy(testValue,sqlite3_column_text(sqlStat,0),sqlite3_column_bytes(sqlStat,0));


-- 
View this message in context: 
http://www.nabble.com/first-few-characters-of-varchar%28%29-corrupted-when-SELECTing-from-a-C%2B%2B-program--tp24237176p24266020.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] first few characters of varchar() corrupted when SELECTing from a C++ program?

2009-06-27 Thread Igor Tandetnik
uralmaza...@pop3.ru wrote:
> sqlite3_open_v2( "testdat", sqlDB, SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE, NULL );
> sqlite3_prepare_v2( sqlDB, "SELECT b FROM whee WHERE a='bing';", -1,
> sqlStat, NULL );
> sqlite3_step( sqlStat );
> const unsigned char *testValue = sqlite3_column_text( sqlStat, 0 );
>
> both a and b are varchar(20)s
>
> calling the query from the command-line tool returns the proper
> result "bang", however, running this code the value testValue shows
> up as ""

Shows up where? How do you examine the string?

Are you examining testValue immediately after sqlite3_column_text call? 
sqlite3_column_text returns a pointer to an internal buffer that may be 
reused by many other calls. If you need to keep the string around for 
later use, you must make a copy of it right after sqlite3_column_text.

Igor Tandetnik



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