Re: [sqlite] C++ - nothing has been stored!!??

2012-07-24 Thread Igor Tandetnik

On 7/24/2012 9:27 PM, Arbol One wrote:

void mySQLite3Class::write(const Glib::ustring& sql_stmt, int pos,  int data
)throw(someException) {
 rc = sqlite3_prepare_v2(db, sql_stmt.c_str(), -1, &stmt, NULL);

 if(rc != SQLITE_OK) { throw(someException)}

 rc = sqlite3_bind_int(stmt, pos, data);

 if(rc != SQLITE_OK) { throw(someException)   }
}

but this does not store anything in the database table.


A hint: which SQLite API function does createTable() call but write() 
doesn't?


Also, don't forget to sqlite3_finalize all prepared statements once you 
are done with them.

--
Igor Tandetnik

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


[sqlite] C++ - nothing has been stored!!??

2012-07-24 Thread Arbol One
And here I am again, asking for what you find so easy and I. well, just
cannot understand.

I am trying to write to a database table previously created by another
process like this:

void someClass::create_tblName() {

sql_param_tblName = "CREATE TABLE name(n_id INTEGER PRIMARY KEY, title
TEXT, fname TEXT, mname TEXT, lname TEXT)";

try {db->createTable(sql_param_tblName); } catch(someException& e) {...}

}

void mySQLite3Class::createTable(const Glib::ustring& s) throw
(someException) {

rc = sqlite3_prepare_v2( db, s.c_str(), -1, &stmt, NULL);

if(rc != SQLITE_OK ) { throw someException }

rc = sqlite3_step(stmt);

if(rc != SQLITE_DONE) { throw someException }

}

}

 

The actual writing to the table looks like this:

 

void someClass::write2tblName() {

stmtName = "INSERT INTO name (n_id, title, fname, mname, lname) VALUES
(?, ?, ?, ?, ?)";

int data1 = 10;

int pos = 1;

try{db->write(stmtName,pos, data1);}catch(someException){.}

}

void mySQLite3Class::write(const Glib::ustring& sql_stmt, int pos,  int data
)throw(someException) {

rc = sqlite3_prepare_v2(db, sql_stmt.c_str(), -1, &stmt, NULL);

if(rc != SQLITE_OK) { throw(someException)}

rc = sqlite3_bind_int(stmt, pos, data);

if(rc != SQLITE_OK) { throw(someException)   }

 

}

 

but this does not store anything in the database table. I have used an
sqlite browser to determine if, in fact, some data was stored, but no,
nothing has been stored.

What am I doing wrong?

 

 

Leonardo da Vinci:
"I have offended God and mankind because my work did not reach the quality
it should have"

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


Re: [sqlite] C++ - sqlite3_extended_result_codes(

2012-07-24 Thread Arbol One
Thanks everyone, I just wanted to be sure.

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Richard Hipp
Sent: Tuesday, July 24, 2012 4:16 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] C++ - sqlite3_extended_result_codes(

On Tue, Jul 24, 2012 at 4:13 PM, Arbol One  wrote:

> I would like to turn on the extended result codes, however, the 
> prototype below does not explain what the value for the second parameter
should be.
>
> Can anybody help?
>
> int sqlite3_extended_result_codes(sqlite3*, int onoff);




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


Re: [sqlite] C++ - sqlite3_extended_result_codes(

2012-07-24 Thread Richard Hipp
On Tue, Jul 24, 2012 at 4:13 PM, Arbol One  wrote:

> I would like to turn on the extended result codes, however, the prototype
> below does not explain what the value for the second parameter should be.
>
> Can anybody help?
>
> int sqlite3_extended_result_codes(sqlite3*, int onoff);
>

zero means turn it off.  non-zero means turn it on.


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



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


Re: [sqlite] EXT : C++ - sqlite3_extended_result_codes(

2012-07-24 Thread Black, Michael (IS)
Should be this:



on = true = !0 = 1 (other !=0 values also work typically)

off = false = 0





Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems


From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Arbol One [arbol...@gmail.com]
Sent: Tuesday, July 24, 2012 3:13 PM
To: SqLite
Subject: EXT :[sqlite] C++ - sqlite3_extended_result_codes(

I would like to turn on the extended result codes, however, the prototype
below does not explain what the value for the second parameter should be.

Can anybody help?

int sqlite3_extended_result_codes(sqlite3*, int onoff);



TIA

___
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] C++ - sqlite3_extended_result_codes(

2012-07-24 Thread Marc L. Allen
I would assume that onoff is either zero or non-zero.  Zero turns off the 
extended codes, non-zero turns them on.

The code seems to support that, but I didn't delve too deeply.

Marc

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Arbol One
Sent: Tuesday, July 24, 2012 4:13 PM
To: SqLite
Subject: [sqlite] C++ - sqlite3_extended_result_codes(

I would like to turn on the extended result codes, however, the prototype below 
does not explain what the value for the second parameter should be.

Can anybody help?

int sqlite3_extended_result_codes(sqlite3*, int onoff);

 

TIA

___
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] C++ - sqlite3_extended_result_codes(

2012-07-24 Thread Arbol One
I would like to turn on the extended result codes, however, the prototype
below does not explain what the value for the second parameter should be.

Can anybody help?

int sqlite3_extended_result_codes(sqlite3*, int onoff);

 

TIA

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


Re: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

2012-07-24 Thread Joe Mistachkin

Bernhard Mogens Ege wrote:
> 
> Has _anyone_ made ":memory:;cache=shared" work in C#/System.Data.SQLite?
> 

I think you want "FullUri=file::memory:?cache=shared;" instead (using the
code
on trunk).

--
Joe Mistachkin

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


Re: [sqlite] SQLite4 key encoding -- Is it ever decoded?

2012-07-24 Thread Nico Williams
On Tue, Jul 24, 2012 at 8:29 AM, Steven E. Harris  wrote:
> Richard Hipp  writes:
>> Many keys can be decoded, but for TEXT keys with application-defined
>> collating sequences, the encoding is not reversible. Many applications
>> will use the ucol_getSortkey() interface to ICU to get the TEXT keys,
>> and there is no way to reverse that encoding to recover the original
>> text.
>
> I take it that in this case, the key encoding is not bijective; rather,
> the encoding is a surjective function, collapsing multiple source values
> into the same encoded value.

If you want normalization-insensitive matching/collating, or if you
want case-insensitivity (and the standard Unicode collations basically
are), then it does indeed follow that getSortkey must be surjective
(because you can construct two strings that compare equal, and
therefore the getSortkey output for them must also be equal).  If we
ignore normalization you can have a bijective getSortkey type of
function for *some* collations, though there's little value in making
it easy to revert given that in the common case getSortkey must be
surjective.

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


Re: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

2012-07-24 Thread Bernhard Mogens Ege
Finally made it work, but still not automatic...

I added those projects from 1.0.81.0 but their resulting DLLs weren't copied
to the target directory. I don't know why. I could copy them manually there,
though. The DLL from SQLite.Interop.2010 was named System.Data.SQLite.dll
and I had to manually rename it to SQLite.Interop.dll and copy it to the
target directory. I kind of expected this to happen automatically. :-/

I also added SQLite.Designer.2010.

And I had to add this to my app.config:


  

  
  

  


Once I did that, my application finally could talk with SQLite 3.7.13! :D

But, alas, shared cache functionality was not available.

I guess I have to revert to using file-based sqlite3 and accept sluggish
performance. For now. At least I hope we get shared memory sqlite3 databases
for C# soon. :)

Seeing as the already tried things didn't work, I might as well revert to
the standard compiled distribution. At least it is less of a hassle to work
with. :-P
-- 
Bernhard

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Bernhard Mogens Ege
Sent: 24. juli 2012 14:43
To: 'General Discussion of SQLite Database'
Subject: Re: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

I have now done nearly exactly as you wrote, with these differences:

I have added the project System.Data.SQLite.Linq.2010 as well and made it
depend on System.Data.SQLite.2010.

I did not disable the XML generation.

I made my project depend on System.Data.SQLite.2010 and
System.Data.SQLite.Linq.2010.

I can build the project just fine, but I cannot run it. I get this error:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.ArgumentException: The specified store provider cannot be found in
the configuration, or is not valid. ---> System.ArgumentException: Unable to
find the requested .Net Framework Data Provider.  It may not be installed.
at System.Data.Common.DbProviderFactories.GetFactory(String
providerInvariantName)   at
System.Data.EntityClient.EntityConnection.GetFactory(String providerString)

I have no other System.Data.SQLite installed on my system and hence the GAC
is does not contain SQLite.

Do I need to do something special for the actual code from SQLite to be
included in my project (i.e. 1 assembly or referenced dlls)?

--
Bernhard

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Bernhard Mogens Ege
Sent: 23. juli 2012 12:05
To: sqlite-users@sqlite.org
Subject: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

I am trying to figure out how to compile System.Data.SQLite and in the
process update sqlite from 3.7.12.1 to 3.7.13 as I need the shared cache
option for memory connections.

 

And when I write 'trying' I am having trouble figuring out where exactly
System.Data.SQLite picks up sqlite3.dll from. The source code doesn't
include it and the installer also doesn't include it, but it must be
somewhere.

 

Is it even safe to update System.Data.SQLite 1.0.81.0 with sqlite3.dll
3.7.13 and will the shared cache feature work?

 

Also, compiling System.Data.SQLite for .NET 4.0 results in some
warnings/errors. Are they safe to ignore?

 

Warning1   The parent file, 'SR.resx',
for file 'SR.Designer.cs' cannot be found in the project file.
System.Data.SQLite.2010

Warning2   Load of property 'OutputType'
failed.System.Data.SQLite.Module.2010

Warning3   The parent file, 'SR.resx',
for file 'SR.Designer.cs' cannot be found in the project file.
System.Data.SQLite.Module.2010

Warning4   Error 2005: Mapping
Association 'FK_InternationalOrders_OrderID_OrderID' is redundant: Its
referential integrity constraint provides sufficient information.  You can
safely delete the mapping information for this association.
C:\Users\bme\Documents\Visual Studio
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
793  800  testlinq.2010

Warning5   Error 2005: Mapping
Association 'FK_OrderDetails_OrderID_OrderID' is redundant: Its referential
integrity constraint provides sufficient information.  You can safely delete
the mapping information for this association.
C:\Users\bme\Documents\Visual Studio
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
801  809  testlinq.2010

Warning6   Error 2005: Mapping
Association 'FK_OrderDetails_ProductID_ProductID' is redundant: Its
referential integrity constraint provides sufficient information.  You can
safely delete the mapping information for this association.
C:\Users\bme\Documents\Vi

Re: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

2012-07-24 Thread J Decker
also have to select x86(win32) or x64(x64) as a build type for the
interop module.  Everything else needs to build as Any CPU.

On Tue, Jul 24, 2012 at 5:42 AM, Bernhard Mogens Ege  wrote:
> I have now done nearly exactly as you wrote, with these differences:
>
> I have added the project System.Data.SQLite.Linq.2010 as well and made it
> depend on System.Data.SQLite.2010.
>
> I did not disable the XML generation.
>
> I made my project depend on System.Data.SQLite.2010 and
> System.Data.SQLite.Linq.2010.
>
> I can build the project just fine, but I cannot run it. I get this error:
>
> Unhandled Exception: System.Reflection.TargetInvocationException: Exception
> has been thrown by the target of an invocation. --->
> System.ArgumentException: The specified store provider cannot be found in
> the configuration, or is not valid. ---> System.ArgumentException: Unable to
> find the requested .Net Framework Data Provider.  It may not be installed.
> at System.Data.Common.DbProviderFactories.GetFactory(String
> providerInvariantName)   at
> System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
>
> I have no other System.Data.SQLite installed on my system and hence the GAC
> is does not contain SQLite.
>
> Do I need to do something special for the actual code from SQLite to be
> included in my project (i.e. 1 assembly or referenced dlls)?
>
> --
> Bernhard
>
> -Original Message-
> From: sqlite-users-boun...@sqlite.org
> [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Bernhard Mogens Ege
> Sent: 23. juli 2012 12:05
> To: sqlite-users@sqlite.org
> Subject: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll
>
> I am trying to figure out how to compile System.Data.SQLite and in the
> process update sqlite from 3.7.12.1 to 3.7.13 as I need the shared cache
> option for memory connections.
>
>
>
> And when I write 'trying' I am having trouble figuring out where exactly
> System.Data.SQLite picks up sqlite3.dll from. The source code doesn't
> include it and the installer also doesn't include it, but it must be
> somewhere.
>
>
>
> Is it even safe to update System.Data.SQLite 1.0.81.0 with sqlite3.dll
> 3.7.13 and will the shared cache feature work?
>
>
>
> Also, compiling System.Data.SQLite for .NET 4.0 results in some
> warnings/errors. Are they safe to ignore?
>
>
>
> Warning1   The parent file, 'SR.resx',
> for file 'SR.Designer.cs' cannot be found in the project file.
> System.Data.SQLite.2010
>
> Warning2   Load of property 'OutputType'
> failed.System.Data.SQLite.Module.2010
>
> Warning3   The parent file, 'SR.resx',
> for file 'SR.Designer.cs' cannot be found in the project file.
> System.Data.SQLite.Module.2010
>
> Warning4   Error 2005: Mapping
> Association 'FK_InternationalOrders_OrderID_OrderID' is redundant: Its
> referential integrity constraint provides sufficient information.  You can
> safely delete the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
> 2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 793  800  testlinq.2010
>
> Warning5   Error 2005: Mapping
> Association 'FK_OrderDetails_OrderID_OrderID' is redundant: Its referential
> integrity constraint provides sufficient information.  You can safely delete
> the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
> 2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 801  809  testlinq.2010
>
> Warning6   Error 2005: Mapping
> Association 'FK_OrderDetails_ProductID_ProductID' is redundant: Its
> referential integrity constraint provides sufficient information.  You can
> safely delete the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
> 2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 810  818  testlinq.2010
>
> Warning7   The referenced component
> 'mscorlib' could not be found.
>
> Warning8   The referenced component
> 'mscorlib' could not be found.
>
>
>
> --
>
> Bernhard
>
> ___
> 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-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQLite4 key encoding -- Is it ever decoded?

2012-07-24 Thread Richard Hipp
On Tue, Jul 24, 2012 at 9:29 AM, Steven E. Harris  wrote:

>
> If, as you say, SQLite cannot (or will not) extract values from an
> encoded key, then does the covering index really just encode column
> values a and b as the key, and store values for c and d in a record
> corresponding to the key?
>

Yes

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


Re: [sqlite] SQLite4 key encoding -- Is it ever decoded?

2012-07-24 Thread Simon Slavin

On 24 Jul 2012, at 2:29pm, "Steven E. Harris"  wrote:

> A (too) literal reading of this would suggest that the index is the
> key-encoded concatenation of -- to use the example from that first Wiki
> page -- four values for columns a, b, c, and d. However, if one were to
> query for c and d while only constraining a and b, then the values for
> columns c and d would need to be extracted from the encoded key.
> 
> If, as you say, SQLite cannot (or will not) extract values from an
> encoded key, then does the covering index really just encode column
> values a and b as the key, and store values for c and d in a record
> corresponding to the key?

The encoding function may be a trapdoor function.  For instance, consider 
COLLATE NOCASE in SQLite3.  In this, the case of the text is ignored, allowing 
the sequence 'xxx','YY','z' to be considered as ordered.  So the value stored 
in the key does not need to have all the detail of the original field: it might 
lose the case of text, or any accents over letters, or some other detail not 
needed for that particular type of collation.  And therefore it may be 
impossible to work backwards from the key values to the values stored in the 
field.

I have an application in which I define a 'DISTANCE' collation, which simply 
drops the sign of the numeric field, since for the purposes of a search I care 
only about how far apart two things are, not which one is to the west of the 
other.  In this case it's impossible to work backwards from the value stored in 
the index and figure out whether the value stored is negative or positive.

I don't know whether SQLite4 actually does work like that.

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


Re: [sqlite] SQLite4 key encoding -- Is it ever decoded?

2012-07-24 Thread Steven E. Harris
Richard Hipp  writes:

> It would be convenient to be able to decode the keys.  But it is not
> possible to do so, in general.

This, then, takes my inquiry to the topic of covering indices.

On the "The Design of SQLite4" Wiki page¹, it says (emphasis mine):

,[ Section 3.6 Explicit Cover Index, paragraph 2 ]
| The COVERING clause makes the values of c and d available in the index,
| which means that they can be /extracted directly from the index/ without
| a second lookup.
`

and

,[ Section 3.6 Explicit Cover Index, paragraph 3 ]
| The COVERING ALL clause means that all columns of the table are
| /duplicated in the index/ which guarantees that the original table will
| never have to be consulted to complete a query that uses the index.
`

The Wiki page "Query Planning" contains a similarly abstract
description:

,[ Query Planning, Section 1.7 Covering Indices ]
| This new index contains all the columns of the original FruitsForSale
| table that are used by the query - both the search terms and the
| output. We call this a "covering index". Because all of the information
| needed is in the covering index, SQLite never needs to consult the
| original table in order to find the price.
`

A (too) literal reading of this would suggest that the index is the
key-encoded concatenation of -- to use the example from that first Wiki
page -- four values for columns a, b, c, and d. However, if one were to
query for c and d while only constraining a and b, then the values for
columns c and d would need to be extracted from the encoded key.

If, as you say, SQLite cannot (or will not) extract values from an
encoded key, then does the covering index really just encode column
values a and b as the key, and store values for c and d in a record
corresponding to the key?

> Many keys can be decoded, but for TEXT keys with application-defined
> collating sequences, the encoding is not reversible. Many applications
> will use the ucol_getSortkey() interface to ICU to get the TEXT keys,
> and there is no way to reverse that encoding to recover the original
> text.

I take it that in this case, the key encoding is not bijective; rather,
the encoding is a surjective function, collapsing multiple source values
into the same encoded value.


Footnotes: 
¹ http://www.sqlite.org/src4/doc/trunk/www/design.wiki

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


Re: [sqlite] C++ - Creating Table

2012-07-24 Thread Robert Myers

On 7/23/2012 10:51 PM, Keith Medcalf wrote:

And of course, finalize after close is wrong.  You finalize the statement, then 
close the db, then bail.
Which goes back to the point I was making, don't manage resources 
yourself. Let the compiler do it. The close should've been only in the 
database object destructor (or, for more flexibility, in a close method 
that happens to be called by the destructor).


Ideally, you should never be using any of the sqlite handle types 
anywhere in your code, except for the objects that manage them. This is 
probably not obtainable in practice without a lot of work and/or 
performance impacting code, or using someone else's library. No matter 
what though, all the creation / destruction calls should be through the 
object, since that's where it really matters.



---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org



-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
boun...@sqlite.org] On Behalf Of Robert Myers
Sent: Monday, 23 July, 2012 21:44
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] C++ - Creating Table

On 7/23/2012 7:43 PM, Arbol One wrote:

Thank you Michael for your prompt response.
I have been able to duplicate the error message. I think this could be a

bug

in SQLite3.
void jme::mySQLite3::createTable(const std::string& s) throw
(std::exception) {
  rc = sqlite3_prepare_v2( db, s.c_str(), -1, &stmt, NULL);
  if(rc != SQLITE_OK) {

rc is a bool, not an int, you have a type coercion error here.


  sqlite3_close(db);
  sqlite3_finalize(stmt);
  std::string error("Error prepare_v2: ");
  error += sqlite3_errmsg(db);
  std::cout << "Error: " << rc << " " << error << std::endl;
  }
  rc = sqlite3_step(stmt);

There's a use after free error here  (you don't return / throw after
finalizing)

  std::cout << "Error: " << rc << std::endl;

  if(rc != SQLITE_DONE) {

And another type coercion error here. rc will never be equal to SQLITE_DONE.


  sqlite3_close(db);
  sqlite3_finalize(stmt);

And another use after free here, since the step will fail, you'll close
it again. Of course, that assumes the step isn't going to crash in the
first place.

  std::string error("error sqlite3_step: ");
  error += sqlite3_errmsg(db);
  std::cout << error << std::endl;
  }
  sqlite3_finalize(stmt);

And another use after free here, same problem with the error handling.

You're committing one of the cardinal sins of C++. Let the compiler do
all the work, don't do it yourself, you'll (generic you) screw it up.
Wrap the DB and query in objects that handle the clean up for you.

Compile everything (except sqlite3.c itself) at the highest possible
warning level treating warnings as errors. That would've caught the type
error. It's one of the first things I set up with new projects.

Rob

___
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-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] read sql script file

2012-07-24 Thread Black, Michael (IS)
You're going to get questions like "why do you want to do this" so you may as 
well tell us now.

The usual way to do his is to execute the sql yourself using statement prepares 
and step.  It gives you a lot more control over error messages.  Why don't you 
want to do it this way?

The 2nd way commonly done is to simply call sqlite3.exe as a system call or a 
pipe.  Less control but easy to understand.

Trying to use the ".read" function by linking it in seems like a bad idea as 
you note.  You could've already had the first wo methods done while trying to 
figure that one out.

Here's the 2 methods in an example (please, anybody, feel free to 
criticizeno pride of authorship here at all).
Change popen and pclose to _popen, _pclose for Windows.

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
void dosql(sqlite3 *db,const char *sql)
{
  sqlite3_stmt *stmt;
  int rc=sqlite3_prepare(db,sql,-1,&stmt,0);
  if (rc != SQLITE_OK) {
cerr << "sqlite3_prepare: " << sqlite3_errmsg(db) << endl;
return;
  }
  rc=sqlite3_step(stmt);
  if (rc == SQLITE_ROW) {
cerr << "multi row sql not implemented: " << sql << endl;
sqlite3_finalize(stmt);
return;
  }
  if (rc != SQLITE_DONE) {
cerr << "sqlite3_step: " << sqlite3_errmsg(db) << endl;
  }
  sqlite3_finalize(stmt);
}
void readfile(char *database,char *sqlfile) {
  sqlite3 *db;
  int rc = sqlite3_open(database,&db);
  if (rc != SQLITE_OK) {
cerr << sqlite3_errmsg(db) << endl;
exit(1);
  }
  ifstream sql;
  sql.open(sqlfile);
  if (!sql.is_open()) {
perror(sqlfile);
exit(1);
  }
  string line;
  while(sql.good()) {
getline(sql,line);
if (!sql.eof()) {
  cerr << "X:" << line << endl;
  dosql(db,line.c_str());
}
  }
  sql.close();
  sqlite3_close(db);
}
void sqlite3_readfile(char *database,char *sqlfile) {
  stringstream ss;
  ss << "sqlite3 " << database << " <" << sqlfile;
  FILE *fp=popen(ss.str().c_str(),"r");
  if (fp == NULL) {
perror("sqlite3");
exit(1);
  }
  char buf[65536];
  while(fgets(buf,sizeof(buf),fp)) {
cout << buf;
  }
  pclose(fp);
}
int main(int argc, char *argv[]) {
  if (argc != 3) {
cerr << "USage: " << argv[0] << " database filename" << endl;
exit(1);
  }
#if 0
  sqlite3_readfile(argv[1],argv[2]);
#else
  readfile(argv[1],argv[2]);
#endif
  return 0;
}


Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems




From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of YAN HONG YE [yanhong...@mpsa.com]
Sent: Tuesday, July 24, 2012 5:16 AM
To: sqlite-users@sqlite.org
Subject: EXT :[sqlite] read sql script file


in the shell.c source file ,have a function .read file, and I wanna use it to 
my c++ code, when I hava a sql script file,such as :

create table test (id integer primary key, value text);
insert into test (id, value) values(1, 'eenie');
insert into test (id, value) values(2, 'meenie');
insert into test (value) values('miny');
insert into test (value) values('mo');

now I wanna use the shell.c function to run the script, but I don't know how to 
use c++ code to  achieve the target.
I only found on line in shell.c:

".read FILENAME Execute SQL in FILENAME\n" in
"static char zHelp[]"

I suggest it use callback.

static int _is_complete(char *zSql, int nSql){
  int rc;
  if( zSql==0 ) return 1;
  zSql[nSql] = ';';
  zSql[nSql+1] = 0;
  rc = sqlite3_complete(zSql);
  zSql[nSql] = 0;
  return rc;
}
___
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] Compiling System.Data.SQLite with latest sqlite3.dll

2012-07-24 Thread Bernhard Mogens Ege
I have now done nearly exactly as you wrote, with these differences:

I have added the project System.Data.SQLite.Linq.2010 as well and made it
depend on System.Data.SQLite.2010.

I did not disable the XML generation.

I made my project depend on System.Data.SQLite.2010 and
System.Data.SQLite.Linq.2010.

I can build the project just fine, but I cannot run it. I get this error:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.ArgumentException: The specified store provider cannot be found in
the configuration, or is not valid. ---> System.ArgumentException: Unable to
find the requested .Net Framework Data Provider.  It may not be installed.
at System.Data.Common.DbProviderFactories.GetFactory(String
providerInvariantName)   at
System.Data.EntityClient.EntityConnection.GetFactory(String providerString)

I have no other System.Data.SQLite installed on my system and hence the GAC
is does not contain SQLite.

Do I need to do something special for the actual code from SQLite to be
included in my project (i.e. 1 assembly or referenced dlls)?

-- 
Bernhard

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Bernhard Mogens Ege
Sent: 23. juli 2012 12:05
To: sqlite-users@sqlite.org
Subject: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

I am trying to figure out how to compile System.Data.SQLite and in the
process update sqlite from 3.7.12.1 to 3.7.13 as I need the shared cache
option for memory connections.

 

And when I write 'trying' I am having trouble figuring out where exactly
System.Data.SQLite picks up sqlite3.dll from. The source code doesn't
include it and the installer also doesn't include it, but it must be
somewhere.

 

Is it even safe to update System.Data.SQLite 1.0.81.0 with sqlite3.dll
3.7.13 and will the shared cache feature work?

 

Also, compiling System.Data.SQLite for .NET 4.0 results in some
warnings/errors. Are they safe to ignore?

 

Warning1   The parent file, 'SR.resx',
for file 'SR.Designer.cs' cannot be found in the project file.
System.Data.SQLite.2010

Warning2   Load of property 'OutputType'
failed.System.Data.SQLite.Module.2010

Warning3   The parent file, 'SR.resx',
for file 'SR.Designer.cs' cannot be found in the project file.
System.Data.SQLite.Module.2010

Warning4   Error 2005: Mapping
Association 'FK_InternationalOrders_OrderID_OrderID' is redundant: Its
referential integrity constraint provides sufficient information.  You can
safely delete the mapping information for this association.
C:\Users\bme\Documents\Visual Studio
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
793  800  testlinq.2010

Warning5   Error 2005: Mapping
Association 'FK_OrderDetails_OrderID_OrderID' is redundant: Its referential
integrity constraint provides sufficient information.  You can safely delete
the mapping information for this association.
C:\Users\bme\Documents\Visual Studio
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
801  809  testlinq.2010

Warning6   Error 2005: Mapping
Association 'FK_OrderDetails_ProductID_ProductID' is redundant: Its
referential integrity constraint provides sufficient information.  You can
safely delete the mapping information for this association.
C:\Users\bme\Documents\Visual Studio
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
810  818  testlinq.2010

Warning7   The referenced component
'mscorlib' could not be found.

Warning8   The referenced component
'mscorlib' could not be found.

 

-- 

Bernhard

___
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] Compiling System.Data.SQLite with latest sqlite3.dll

2012-07-24 Thread Bernhard Mogens Ege
Thank you for the suggestion.

But my binary keeps loading the System.Data.SQLite from the GAC instead of
from the project (I added a reference to the DLL from the System.Data.SQLite
project, seemed like the way to do it).

The dll hell is even worse in .NET. :-/

Has _anyone_ made ":memory:;cache=shared" work in C#/System.Data.SQLite?

The unreleased 1.0.82.0 doesn't work. 1.0.81.0 with 3.7.13 doesn't work. I
wonder what I am missing. :-/
-- 
Bernhard

-Original Message-
From: J Decker [mailto:d3c...@gmail.com] 
Sent: 24. juli 2012 02:49
To: b...@saseco.dk; General Discussion of SQLite Database
Subject: Re: [sqlite] Compiling System.Data.SQLite with latest sqlite3.dll

On Mon, Jul 23, 2012 at 3:04 AM, Bernhard Mogens Ege  wrote:
> I am trying to figure out how to compile System.Data.SQLite and in the 
> process update sqlite from 3.7.12.1 to 3.7.13 as I need the shared 
> cache option for memory connections.
>
>
>
> And when I write 'trying' I am having trouble figuring out where 
> exactly System.Data.SQLite picks up sqlite3.dll from. The source code 
> doesn't include it and the installer also doesn't include it, but it 
> must be somewhere.
>

It is in there in 1.0.80.0\SQLite.Interop\src\core\sqlite3.c

You need 3 projects, the netmodule, the static sqlite library and the
system.data.sqlite project

1.0.80.0\System.Data.SQLite\System.Data.SQLite.Module.2010.csproj
1.0.80.0\SQLite.Interop\SQLite.Interop.Static.2010.vcxproj
1.0.80.0\System.Data.SQLite\System.Data.SQLite.2010.csproj

interop must depend on module
system.data.sqlite must depend on interop  (right click on a project and use
'Project Dependencies' to add the additional dependencies)

Then you can just reference system.data.sqlite.2010 in other projects

Turn off generate XML documentation in build tab of project properties of
system.data.sqlite.module project.  (otherwise it causes it to always
rebuild, and in turn all dependants of it)

Probably similar rules for more recent versions

That is if you want to include building from source in your project;
otherwise you can just use the default solution of sqlite to build a DLL and
add that as the reference.

>
>
> Is it even safe to update System.Data.SQLite 1.0.81.0 with sqlite3.dll
> 3.7.13 and will the shared cache feature work?
>
>
>
> Also, compiling System.Data.SQLite for .NET 4.0 results in some 
> warnings/errors. Are they safe to ignore?
>
>
>
> Warning1   The parent file, 'SR.resx',
> for file 'SR.Designer.cs' cannot be found in the project file.
> System.Data.SQLite.2010
>
> Warning2   Load of property
'OutputType'
> failed.System.Data.SQLite.Module.2010
>
> Warning3   The parent file, 'SR.resx',
> for file 'SR.Designer.cs' cannot be found in the project file.
> System.Data.SQLite.Module.2010
>
> Warning4   Error 2005: Mapping
> Association 'FK_InternationalOrders_OrderID_OrderID' is redundant: Its 
> referential integrity constraint provides sufficient information.  You 
> can safely delete the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
>
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 793  800  testlinq.2010
>
> Warning5   Error 2005: Mapping
> Association 'FK_OrderDetails_OrderID_OrderID' is redundant: Its 
> referential integrity constraint provides sufficient information.  You 
> can safely delete the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
>
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 801  809  testlinq.2010
>
> Warning6   Error 2005: Mapping
> Association 'FK_OrderDetails_ProductID_ProductID' is redundant: Its 
> referential integrity constraint provides sufficient information.  You 
> can safely delete the mapping information for this association.
> C:\Users\bme\Documents\Visual Studio
>
2010\Projects\sqlite-netFx-source-1.0.81.0\testlinq\NorthwindModel2010.edmx
> 810  818  testlinq.2010
>
> Warning7   The referenced component
> 'mscorlib' could not be found.
>
> Warning8   The referenced component
> 'mscorlib' could not be found.
>
>
>
> --
>
> Bernhard
>
> ___
> 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] Tests fail with some glibc malloc/realloc/free-related warnings on Mageia Linux 3/Cauldron with glibc-2.16-2.mga3

2012-07-24 Thread Shlomi Fish
Hi Richard,

On Mon, 23 Jul 2012 12:57:01 -0400
Richard Hipp  wrote:

> On Mon, Jul 23, 2012 at 9:31 AM, Shlomi Fish  wrote:
> 
> >
> > I first suspected svn was the culprit, so I rebuilt it, but it still
> > happened.
> > Then I tried build SQLite and running its tests and I got this (below). I
> > should note that svn works fine after I type "unset MALLOC_CHECK_" in the
> > console (don't know about the sqlite tests).
> >
> > What is the underlying problem and how can it be fixed?
> >
> 
> Thanks for the report.
> 
> As best I can tell, this appears to be a bug in MALLOC_CHECK_ in that it
> does not play well with malloc_usable_size().  There does not appear to be
> anything wrong with SQLite in this respect, at least as not as far as I can
> see.
> 
> We test SQLite using a variety of memory allocator that do things similar
> to MALLOC_CHECK_.  (See http://www.sqlite.org/testing.html#valgrind for
> example.)  In particular, SQLite tests run clean under valgrind.
> 
> If you edit the "config.h" file generated by the ./configure script and
> remove the HAVE_MALLOC_USABLE_SIZE define, then the resulting SQLite will
> not attempt to use malloc_usable_size() and it then appears to work fine
> with MALLOC_CHECK_.  However, if you do this, then SQLite will increase the
> size of every memory allocation by 8 bytes and store the allocation size in
> those 8 bytes so that it can figure out the allocation size for itself when
> it needs it, meaning that the code will run a little slower and use a
> little more memory.
> 

Thanks! After running ./configure, I removed the HAVE_MALLOC_USABLE_SIZE line
and now svn is working nicely with MALLOC_CHECK_=1.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity

COBOL is the old Java.

Please reply to list if it's a mailing list post - http://shlom.in/reply .
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] single gdbconn object with multiple threads.

2012-07-24 Thread Simon Slavin

On 24 Jul 2012, at 6:58am, Durga D  wrote:

> My Req. is: I have to write a wrapper for sqlite3. This wrapper will be
> called by different clients from different threads within the process.
> Requests might be read or write. Wrapper will have static sqlite3*. So all
> clients shares the same sqlite3*. To simulate this, I created this sample
> application.
> 
> doubt: How can I achieve this single thread when multiple clients are
> called.

Because you are starting off with different threads it doesn't matter in this 
case.  You have already organised your client into threads so just continue to 
use the threads that you already have.

We sometimes get questions from people who have made individual threads in 
their program only because they think it will speed up SQLite processing.  This 
is a waste for SQLite because it locks the whole database anyway.  But your 
application uses individual threads for a different reason, and SQLite will 
also handle that okay providing that you haven't messed with anything mentioned 
here:



It won't be much faster or slower than doing all your access using a single 
thread.

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


[sqlite] read sql script file

2012-07-24 Thread YAN HONG YE
in the shell.c source file ,have a function .read file, and I wanna use it to 
my c++ code, when I hava a sql script file,such as :

create table test (id integer primary key, value text);
insert into test (id, value) values(1, 'eenie');
insert into test (id, value) values(2, 'meenie');
insert into test (value) values('miny');
insert into test (value) values('mo');

now I wanna use the shell.c function to run the script, but I don't know how to 
use c++ code to  achieve the target.
I only found on line in shell.c:

".read FILENAME Execute SQL in FILENAME\n" in 
"static char zHelp[]"

I suggest it use callback.

static int _is_complete(char *zSql, int nSql){
  int rc;
  if( zSql==0 ) return 1;
  zSql[nSql] = ';';
  zSql[nSql+1] = 0;
  rc = sqlite3_complete(zSql);
  zSql[nSql] = 0;
  return rc;
}
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users