Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-05 Thread Bob Moran
Thank you guys for the responses. Great info to consider. I was quite
confused but the fact that by waiting some length of time after startup of
the app, that everything appeared to work. I repeated ran the troublesome
call (without stopping the app), and it would work the 6-7 times of making
the call.

Bob Moran


On Fri, Sep 5, 2014 at 10:15 AM, Nelson, Erik - 2 <
erik.l.nel...@bankofamerica.com> wrote:

> Bob Moran wrote on: Friday, September 05, 2014 12:07 AM
> > On Wed, Sep 3, 2014 at 1:29 PM, Nelson, Erik - 2 <
> > erik.l.nel...@bankofamerica.com> wrote:
> >
> > > Bob Moran wrote on Wednesday, September 03, 2014 12:45 PM
> > > >
> > > > One added note: My GUI is using QT4, where in this case the SQL
> > text
> > > > goes something like:
> > > >
> > > >   QString qstr = "select id, step, temp from protocols where id
> > > > = %1";
> > > >   qstr = qstr.arg(id);
> > > >   char * str = (char*)qPrintable(qstr);
> > > >   sqlite3_prepare_v2( db, str, qstr.Length+1, , NULL)
> > > >
> > >
> > > That's pretty different than the pseudocode you presented earlier.
> > >
> > > From the docs for qPrintable
> > > http://qt-project.org/doc/qt-4.8/qtglobal.html#qPrintable
> > >
> > > **
> > > Returns str as a const char *. This is equivalent to
> > > str.toLocal8Bit().constData().
> > >
> > > The char pointer will be invalid after the statement in which
> > > qPrintable() is used. This is because the array returned by
> > > toLocal8Bit() will fall out of scope.
> > > 
> > >
> > > Your str is likely pointing to memory that has been freed?
> > >
> > Are you implying that I must copy the text returned by qPrintable(sql)
> > to a safe location before calling a method that uses it? I thought that
> > the string would be valid until I return from the routine.
>
> Based on my reading of the documentation, yes.
>
> The char pointer will be invalid after the *statement* in which
> qPrintable() is used.
>
> You've already provided additional evidence that your string is pointing
> to unallocated memory... you previously wrote
>
> >Bob Moran wrote on 03. September 2014 06:25
> >>I discovered that a malloc call for 500+ bytes was returning a pointer 8
> bytes below my SQL string
>
> On the face of it, I'd suggest that indicates that the memory pointed by
> your char* has been reallocated since it was returned to the free store.
>
> Also, as Alessandro mentioned, the length you're using is likely
> unreliable.
>
> Erik
>
> --
> This message, and any attachments, is for the intended recipient(s) only,
> may contain information that is privileged, confidential and/or proprietary
> and subject to important terms and conditions available at
> http://www.bankofamerica.com/emaildisclaimer.   If you are not the
> intended recipient, please delete this message.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-04 Thread Bob Moran
Erik,
Are you implying that I must copy the text returned by qPrintable(sql) to a
safe location before calling a method that uses it? I thought that the
string would be valid until I return from the routine.

Bob Moran


On Wed, Sep 3, 2014 at 1:29 PM, Nelson, Erik - 2 <
erik.l.nel...@bankofamerica.com> wrote:

> Bob Moran wrote on Wednesday, September 03, 2014 12:45 PM
> >
> > One added note: My GUI is using QT4, where in this case the SQL text
> > goes something like:
> >
> >   QString qstr = "select id, step, temp from protocols where id
> > = %1";
> >   qstr = qstr.arg(id);
> >   char * str = (char*)qPrintable(qstr);
> >   sqlite3_prepare_v2( db, str, qstr.Length+1, , NULL)
> >
>
> That's pretty different than the pseudocode you presented earlier.
>
> From the docs for qPrintable
> http://qt-project.org/doc/qt-4.8/qtglobal.html#qPrintable
>
> **
> Returns str as a const char *. This is equivalent to
> str.toLocal8Bit().constData().
>
> The char pointer will be invalid after the statement in which qPrintable()
> is used. This is because the array returned by toLocal8Bit() will fall out
> of scope.
> 
>
> Your str is likely pointing to memory that has been freed?
>
> Erik
>
> --
> This message, and any attachments, is for the intended recipient(s) only,
> may contain information that is privileged, confidential and/or proprietary
> and subject to important terms and conditions available at
> http://www.bankofamerica.com/emaildisclaimer.   If you are not the
> intended recipient, please delete this message.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-03 Thread Bob Moran
Thank you for the prompt responses.

Bob Moran

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Simon Slavin
Sent: Wednesday, September 03, 2014 12:41 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After 
Application Startup


On 3 Sep 2014, at 5:18pm, Bob Moran <bmo...@cicaccess.com> wrote:

> I am using the amalgamation. Simply added the SQLITE3.c and .H files to my 
> project. I am developing with VisualGDB (VS 2010) cross compiling (building 
> on Windows 7, running on RPI). No added compiler directives (hopefully, that 
> is the problem).

I'm sorry.  You gave clear answers to my questions but unfortunately they do 
not indicate any problem with your setup.  I hope someone know knows the 
internals of SQLite better than me can help you investigate this.

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


Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-03 Thread Bob Moran
One added note: My GUI is using QT4, where in this case the SQL text goes 
something like:

QString qstr = "select id, step, temp from protocols where id = %1";
qstr = qstr.arg(id);
char * str = (char*)qPrintable(qstr);
sqlite3_prepare_v2( db, str, qstr.Length+1, , NULL)

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Simon Slavin
Sent: Wednesday, September 03, 2014 12:51 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After 
Application Startup


> On 3 Sep 2014, at 5:24am, Bob Moran <bmo...@cicaccess.com> wrote:
> 
> Found more of what the issue is. I noticed that my SQL text was being 
> overwritten on the return from the call to prepare_v2.
> Stepping through the SQlite3 code I discovered that a malloc call for 500+ 
> bytes was returning a pointer 8 bytes below my SQL string.
> Don't have the foggiest notion as to why. My string is on the heap. If I wait 
> some time before making the call (my program is just waiting for input, then 
> the malloc call returns a pointer far removed from my passed in SQL text. 
> Must be some kind on Linux issue?

Are you using a SQLite library or including the amalgamation source code ?

If you're using the SQLite source are you using any SQLite compiler defs ?

Which compiler are you using ?

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


Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-03 Thread Bob Moran
I am using the amalgamation. Simply added the SQLITE3.c and .H files to my 
project. I am developing with VisualGDB (VS 2010) cross compiling (building on 
Windows 7, running on RPI). No added compiler directives (hopefully, that is 
the problem).

Bob Moran
-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Simon Slavin
Sent: Wednesday, September 03, 2014 12:51 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After 
Application Startup


> On 3 Sep 2014, at 5:24am, Bob Moran <bmo...@cicaccess.com> wrote:
> 
> Found more of what the issue is. I noticed that my SQL text was being 
> overwritten on the return from the call to prepare_v2.
> Stepping through the SQlite3 code I discovered that a malloc call for 500+ 
> bytes was returning a pointer 8 bytes below my SQL string.
> Don't have the foggiest notion as to why. My string is on the heap. If I wait 
> some time before making the call (my program is just waiting for input, then 
> the malloc call returns a pointer far removed from my passed in SQL text. 
> Must be some kind on Linux issue?

Are you using a SQLite library or including the amalgamation source code ?

If you're using the SQLite source are you using any SQLite compiler defs ?

Which compiler are you using ?

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


Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-09-02 Thread Bob Moran
Found more of what the issue is. I noticed that my SQL text was being 
overwritten on the return from the call to prepare_v2.
Stepping through the SQlite3 code I discovered that a malloc call for 500+ 
bytes was returning a pointer 8 bytes below my SQL string.
Don't have the foggiest notion as to why. My string is on the heap. If I wait 
some time before making the call (my program is just waiting for input, then 
the malloc call returns a pointer far removed from my passed in SQL text. Must 
be some kind on Linux issue?

Bob Moran

Continental Access / NAPCO Security Technologies
355 Bayview Ave.
Amityville, N.Y. 11701
631.842.9400 x327

rmo...@cicaccess.com


-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Roger Binns
Sent: Tuesday, September 02, 2014 12:45 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Cannot retrieve SQLite Db Data Immediately After 
Application Startup

On 29/08/14 12:55, Bob Moran wrote:
> The return code (rc) is SQLITE_OK, but "stmnt" is NULL (0)
>
> if I start the application and wait for at least 1 minute, everything works.

You get NULL back from prepare with SQLITE_OK if the statement doesn't do 
anything.  Examples are empty strings or comments.  Chances are that is 
actually what is happening in your case.

Roger

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


[sqlite] Cannot retrieve SQLite Db Data Immediately After Application Startup

2014-08-30 Thread Bob Moran
Application running on Linux Debian (Raspberry Pi. I am using QT4 and
 SQLite3.c V3.8.6 embedded in the application).using VisualGDB cross
compiler running in RPI. The problem occurs on first startup.
With the database open via:

sqlite3_open_v2("/home/pi/mydatabase.db", , SQLITE_OPEN_READWRITE, NULL
);

sqlite3_stmt *stmt;

const char s = "select rowid, name from protmaster";

int len = strlen (s);

int rc = sqlite3_prepare_v2(db, s, len+1, , NULL);

if (rc == SQLITE_OK && stmt != NULL)

{

...

}

The return code (rc) is SQLITE_OK, but "stmnt" is NULL (0)

if I start the application and wait for at least 1 minute, everything works.

my application is doing nothing at this point, just waiting for input,
which in my cast is clicking on a button. No multi-threading involved. I
attempted a quick step thru of the code, but kinda got lost in the parsing.
No internal errors were being set

Any suggestions would be appreciated.



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