[sqlite] sqlite error 25 during bind

2016-04-10 Thread Kumar Suraj
Any idea what could be wrong here..

On Sat, Apr 9, 2016 at 5:10 PM, Kumar Suraj  wrote:

> Yes i am calling sqlite3_prepare_v2
>
>  snprintf(command, 512, INSERT_DN);
> if ( (rv = sqlite3_prepare_v2(sqlHandle->db, command, -1,
>  &newStmt, NULL) ) != SQLITE_OK )
> {
>fprintf(stderr, "Error Insert : sqlite3_prepare_v2, Error code
> : %d\n", rv);
>sqlite3_finalize(newStmt);
>return rv;
> }
> rv = sqlite3_bind_blob(newStmt, 1, aInBuffer.ptr, aInBuffer.size,
> SQLITE_STATIC);
> if (rv != SQLITE_OK)
> {
> fprintf(stderr, "Error Insert : sqlite3_bind_blob, Error code
> : %d\n", rv);
> sqlite3_finalize(newStmt);
> return rv;
> }
> rv = sqlite3_bind_int(newStmt, 2 , aInClassId);
> if (rv != SQLITE_OK)
> {
> fprintf(stderr, "Error Insert : sqlite3_bind_int, Error code :
> %d\n", rv);
> sqlite3_finalize(newStmt);
> return rv;
> }
>
>
> On Wed, Apr 6, 2016 at 4:55 PM, Simon Davies  > wrote:
>
>> On 6 April 2016 at 12:16, Kumar Suraj  wrote:
>> > Hi
>> .
>> .
>> .
>> > Here is table definition and insert statement which is causing this
>> >
>> > #define CREATE_TABLE_DNINDEX "CREATE TABLE IF NOT EXISTS TBL (dn BLOB,
>> > pclassid INTEGER, pkey INTEGER, kindex INTEGER PRIMARY KEY ASC)"
>> >
>> > #define INSERT_DN "INSERT INTO TBL (dn,pclassid,pkey) VALUES (?,?,?);"
>> >
>> >  rv = sqlite3_bind_int(newStmt, 2 , aInClassId);
>> >
>> > if (rv != SQLITE_OK)
>> >
>> > {
>> >
>> > fprintf(stderr, "Error Insert : sqlite3_bind_int, Error
>> code :
>> > %d\n", rv);
>> >
>> > sqlite3_finalize(newStmt);
>> >
>> > return rv;
>> >
>> > }
>>
>> Are you calling sqlite3_prepare_v2 before your call to sqlite3_bind_int?
>>
>> Regards,
>> Simon
>> ___
>> sqlite-users mailing list
>> sqlite-users at mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
>
>


[sqlite] Expecting syntax error on delete

2016-04-10 Thread R Smith


On 2016/04/09 5:20 PM, Richard Williams wrote:
> I have a PHP program where I have the equivalent of the following code. The
> code was not deleting the expected rows ('abc' & 'def') because of the bad
> syntax. However the error did not throw an exception. Is this what I should
> expect?
>
> $p = new PDO('sqlite::memory:');
> $p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> $p->exec("create table a (a text)");
> $sql = "delete from a where a in (a in ('abc','def'))";
> $stat = $p->exec($sql);

Yes, you should expect it.

The expression "a in ('abc','def')" returns a boolean value, true or 
false based on what is in "a" at the current record (which is what you 
need for the filtering).

So the larger expression "a in (a in ('abc','def'))" checks whether "a" 
falls inside a set of values that contain a single boolean value (as 
returned by the above expression) - whether that boolean value ends up 
being TRUE or FALSE does not matter, since the "a" won't likely be a 
boolean in itself, but there is absolutely nothing wrong with the 
expression's validity and so no reason to error out or throw an 
exception or even simply complain about the grammar. It simply might not 
find any matches and so not delete any rows.



[sqlite] Expecting syntax error on delete

2016-04-10 Thread Stephan Beal
On Sat, Apr 9, 2016 at 5:20 PM, Richard Williams <
richard at roguewavelimited.com> wrote:

> I have a PHP program where I have the equivalent of the following code. The
> code was not deleting the expected rows ('abc' & 'def') because of the bad
> syntax. However the error did not throw an exception. Is this what I should
> expect?
>
> $p = new PDO('sqlite::memory:');
> $p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> $p->exec("create table a (a text)");
> $sql = "delete from a where a in (a in ('abc','def'))";
> $stat = $p->exec($sql);
>

('abc' & 'def') does not produce a syntax error:

sqlite> select 'abc' & 'def';
0

so your SQL was well-formed, just not what you wanted. Your IN(...)
effectively resolved to IN(0).

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf


[sqlite] Expecting syntax error on delete

2016-04-10 Thread Simon Slavin

On 9 Apr 2016, at 4:20pm, Richard Williams  
wrote:

> The
> code was not deleting the expected rows ('abc' & 'def') because of the bad
> syntax. However the error did not throw an exception. Is this what I should
> expect?

There was no exception because SQLite successfully understood your command.  
Your SQL command is actually legal.  However if you inspect the properties of 
$stat you should get some understanding of what went wrong.

PHP/SQLite3 tip:

If you want better integration with SQLite and aren't going to convert your 
code to work with other SQL engines. it is far better to use PHP's own sqlite3 
library rather than the generic PDO library.  This gives you finer control over 
SQLite's features and removes the need to learn both PDO and SQLite structures 
and techniques.  It's faster and keeps files locked for less time, too.

On the other hand, if you're using SQLite3 for testing only and your production 
code is actually going to work on some other engine, you'll be better off as 
you are using the PDO library.

Simon.


[sqlite] sqlite error 25 during bind

2016-04-10 Thread Olivier Mascia
Le 10 avr. 2016 ? 14:12, Kumar Suraj  a ?crit :
> 
> Any idea what could be wrong here..

Have you checked the return value of sqlite3_bind_parameter_count(newStmt) 
after successful call to sqlite3_prepare_v2()?

I would also output the string returned by sqlite3_sql(newStmt) in your error 
paths, just to be clear the prepared statement is really the one you expect.

-- 
Meilleures salutations, Met vriendelijke groeten, Best Regards,
Olivier Mascia, integral.be/om





[sqlite] sqlite error 25 during bind

2016-04-10 Thread Simon Slavin

On 10 Apr 2016, at 1:12pm, Kumar Suraj  wrote:

> Any idea what could be wrong here..

The error indicates you're trying to bind to, for example, item 4 when the 
string only has two binding points.

Use a debugger to show the string you're binding to at the last possible point.

Simon.