[sqlite] Running Sqlite on 64-bit/Client-server data base

2015-12-15 Thread Bernardo Sulzbach
It runs on 64-bit computers.

It does not need a special process to serve other processes.

Read the documentation to answer trivial questions like these.

On Tue, Dec 15, 2015 at 9:47 PM, Hamdan Alabsi
 wrote:
> Greetings Everyone,
> Hope all is well. I am wondering if I can run Sqlite on 64-bit machine?
> Also, does sqlite support client-server database engine ? I hope I can get
> the answers from you very soon. Thank you.
>
> Best regards,
> Hamdan
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



-- 
Bernardo Sulzbach


[sqlite] Problem with accumulating decimal values

2015-12-15 Thread James K. Lowden
On Fri, 11 Dec 2015 16:21:30 +0200
"Frank Millman"  wrote:

> sqlite> UPDATE fmtemp SET balance = balance + 123.45;
> sqlite> SELECT bal FROM fmtemp;
> 5925.599

To a question like that you'll receive a lot of answers about numerical
accuracy.  And it's true that there are ways to "do the math" without
using floating point representation.  It's also true that it's rarely
necessary, which is why floating point representation exists and *is*
widely used.  You may find it works for you too, unless you have to
adhere to a specific rounding policy.  

Per your example, you're working with 2 decimal places of precision.
5925.599 rounds off to 5925.60; it even rounds off to
5925.60, not too shabby.  If you keep adding 123.45 to it,
you'll find you can go on forever before the answer is wrong in the
second decimal place.  

IEEE 754 is a solid bit of engineering.  It's capable of representing
15 decimal digit of precision.  That's good enough to measure the
distance to the moon ... in millimeters.  

You could have an exceptional situation, but that would be
exceptional.  Usually, double-precision math works just fine, provided
you have some form of round(3) at your disposal when it comes time to
render the value in decimal form.  

--jkl


[sqlite] about attach database

2015-12-15 Thread Richard Hipp
On 12/15/15, ??? <2004wqg2008 at 163.com> wrote:
>I mean only compare the two ways of  get the database handl.
>   1.sqlite3_open
>   2.ATTACH DATABASE

I think they both do about the same amount of work.

-- 
D. Richard Hipp
drh at sqlite.org


[sqlite] about attach database

2015-12-15 Thread Richard Hipp
On 12/15/15, ??? <2004wqg2008 at 163.com> wrote:
> hi,all
>  There are two ways to open a database.
>  1.sqlite3_open
>  2.ATTACH DATABASE
>
>  Because there are so many data base. So we used attach database to open
> them.
>  But the efficiency of the programming is not ideal.
>
>  which one is faster?
>  Is the efficiency between the two methods great?
>

I think both methods are about the same speed.  Have you measured a
difference between them?  They both do about the same amount of work,
I think.

-- 
D. Richard Hipp
drh at sqlite.org


[sqlite] about attach database

2015-12-15 Thread Jim Dodgen
You cannot attach to this list. If you can just paste into the body of the
email or provide a link to the information

*Jim Dodgen*







On Tue, Dec 15, 2015 at 9:33 PM, ??? <2004wqg2008 at 163.com> wrote:

>
> After testing the Sqlite3_open and ATTACH DATABASE,
> I found that the attach database is slower than sqlite3_open.
> there is attachment after the mail which includ the speed
> information ( millisecond ).
>
>
>
> At 2015-12-16 10:59:27, "Richard Hipp"  wrote:
> >On 12/15/15, ??? <2004wqg2008 at 163.com> wrote:
> >>I mean only compare the two ways of  get the database handl.
> >>   1.sqlite3_open
> >>   2.ATTACH DATABASE
> >
> >I think they both do about the same amount of work.
> >
> >--
> >D. Richard Hipp
> >drh at sqlite.org
> >___
> >sqlite-users mailing list
> >sqlite-users at mailinglists.sqlite.org
> >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>


[sqlite] Geting the errorcode in Java

2015-12-15 Thread Cecil Westerhof
2015-12-15 18:51 GMT+01:00 gwenn :

> Your code looks good to me.
> You should report an issue here: https://github.com/xerial/sqlite-jdbc
>

?Done.?


-- 
Cecil Westerhof


[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Stephen Chrzanowski
I work for a flight planning software house, so I had to take a double-look
at this.  Competition, eh? ;)

On Tue, Dec 15, 2015 at 4:14 PM, Richard Hipp  wrote:

>
>
> Interesting timing:  I was monitoring an inbound flight on flightaware
> when this issue report arrived in my inbox.  :-)
>
> --
> D. Richard Hipp
> drh at sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Karl Lehenbauer
Consider the following table definitions:


DROP TABLE IF EXISTS flightplans;


CREATE TABLE flightplans (

id text NOT NULL,

ident text,

recvd integer,

orig text,

dest text,

PRIMARY KEY (id)

);



DROP TABLE IF EXISTS inflight;


CREATE TABLE inflight (

fp text,

ident text,

alt integer,

clock integer NOT NULL DEFAULT 0,

gs integer,

heading integer,

lat real,

lon real,

reg text,

squawk int,

primary key (fp)

);


It is an error to select a column that doesn?t exist?


sqlite> select fp from flightplans;

Error: no such column: fp

But if I select a column that doesn?t exist within an embedded subquery, it is 
not an error?


sqlite> delete from inflight where fp in (select fp from flightplans);

sqlite>

(In the above example, unless I am mistaken, it should produce more or less the 
same ?no such column? error.)

In my ?real life? version of this stuff where it has a fair number of rows in 
the tables, it appears to be an infinite loop, like with < 100K rows in each 
table I aborted the statement after more than 20 minutes of CPU time.




[sqlite] Geting the errorcode in Java

2015-12-15 Thread gwenn
Hello,
Your code looks good to me.
You should report an issue here: https://github.com/xerial/sqlite-jdbc
Regards.

On Mon, Dec 14, 2015 at 8:38 PM, Cecil Westerhof  
wrote:
> I have the following code:
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.Statement;
> import java.sql.SQLException;
>
>
> public class CheckProverbsLocked {
> private CheckProverbsLocked() {
> }
>
> public static void main(String [] args) throws Exception {
> Connection   conn;
> Statementstmt;
>
> Class.forName("org.sqlite.JDBC");
> conn = DriverManager.getConnection("jdbc:sqlite:proverbs.sqlite");
> stmt  = conn.createStatement();
> try {
> stmt.executeUpdate("begin immediate");
> } catch (SQLException e) {
> System.out.println(e.getErrorCode());
> System.out.println(e.getMessage());
> System.out.println(e.getSQLState());
> }
> stmt.close();
> conn.close();
> }
>
> }
>
>
> I get the following output when the database is locked:
> 0
> database is locked
> null
>
> I would expect the first one to be 5. What am I doing wrong?
>
> --
> Cecil Westerhof
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Running Sqlite on 64-bit/Client-server data base

2015-12-15 Thread Hamdan Alabsi
Greetings Everyone,
Hope all is well. I am wondering if I can run Sqlite on 64-bit machine?
Also, does sqlite support client-server database engine ? I hope I can get
the answers from you very soon. Thank you.

Best regards,
Hamdan


[sqlite] 回复: Why SQLITE_BUSY?

2015-12-15 Thread sanhua.zh
oh, sorry, I make this mistake.


Another question is that if ?sqlite3_prepare? fail, do I need to 
?sqlite3_finalize? the stmt. Here is the sample code,


int ret = sqlite3_prepare(handle, ?some sql?, stmt, ?);
if (ret==SQLITE_OK) {
//step
sqlite3_finalize(stmt);
}else {
//log error
//should I finalize stmt here?
//sqlite3_finalize(stmt);
}





???:Hick Gunterhick at scigames.at
???:'SQLite mailing list'sqlite-users at mailinglists.sqlite.org
:2015?12?15?(??)?17:42
??:Re: [sqlite] ??? Why SQLITE_BUSY?


It looks like you have unfinalized statements in your transaction. You are 
preparing statements inside the loop, but finalizing only 1 (the last) 
statement. And attempting to commit even before finalizing only the last 
statement. So sqlite3_close() is complaining about improper call sequence, not 
interference from any other process/thread. -Urspr?ngliche Nachricht- 
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von 
sanhua.zh Gesendet: Dienstag, 15. Dezember 2015 10:27 An: SQLite mailing list 
Betreff: [sqlite] ??? Why SQLITE_BUSY? I?m very excited that I re-produce the 
SQLITE_BUSY code in a simple demo. Here is my test code, void 
showResultCode(int resultCode) { if 
(resultCode!=SQLITE_DONEresultCode!=SQLITE_OKresultCode!=SQLITE_ROW) { 
NSLog(@"unexperted result %d", resultCode); } } void SQLiteLog(void* userInfo, 
int ret, const char* msg) { NSLog(@"ret=%d, msg=%s", ret, msg); } void 
write(const char* path) { int code = SQLITE_OK; sqlite3* handle; 
showResultCode(sqlite3_open(path, handle)); sqlite3_exec(handle, "PRAGMA 
journal_mode=WAL", nullptr, nullptr, nullptr); sqlite3_exec(handle, "create 
table test(id integer);", nullptr, nullptr, nullptr); sqlite3_stmt* stmt = 
nullptr; showResultCode(sqlite3_exec(handle, "BEGIN IMMEDIATE", nullptr, 
nullptr, nullptr)); for (int i = 0; i 2; i++) { 
showResultCode(sqlite3_prepare(handle, [NSString stringWithFormat:@"insert into 
test values(%d);", i].UTF8String, -1, stmt, nullptr)); 
showResultCode(sqlite3_step(stmt)); } showResultCode(sqlite3_exec(handle, 
"COMMIT", nullptr, nullptr, nullptr)); showResultCode(sqlite3_finalize(stmt)); 
showResultCode(sqlite3_close(handle)); } int main(int argc, char * argv[]) { 
sqlite3_config(SQLITE_CONFIG_LOG, SQLiteLog, NULL); const char* path = 
"/Users/sanhuazhang/Desktop/test.db"; write(path); return 1; } The console 
result is ?unexperted result 5?, which indicates SQLITE_BUSY. It happens at 
code?sqlite3_close?.one of the strange things is that?SQLiteLog? print nothing. 
AndYou can see that I only write some data using transaction. How could 
SQLITE_BUSY happened while sqlite.org said that?The SQLITE_BUSY result code 
indicates that the database file could not be written (or in some cases read) 
because of concurrent activity by some other database connection.?. So, as a 
conclusion, I confuse that why the result code of?sqlite3_close" is SQLITE_BUSY 
and is it possible that SQLITE_BUSY returned by other function in this 
situation(single process,single thread,single connection).  
???:sanhua.zhsanhua.zh at foxmail.com ???:sqlite-userssqlite-users at 
mailinglists.sqlite.org :2015?12?14?(??)?17:21 ??:[sqlite] Why SQLITE_BUSY? 
I queue all my db operation into one thread with single sqlite conn. neither 
multi-thread nor multi-process operation happened.But some SQLITE_BUSY error 
code still be catched. I can not re-produce this error code indeveloping 
environment,because it happen in alow probability. I only catch this error 
report online. So how did it happen? I guess that, when WAL reach the 
checkpoint, sqlite will write the data back to original db file in background 
thread. So writing will be busy at this time. But I?m not sure. I hope that you 
will not stint your criticism ___ 
sqlite-users mailing list sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users 
___ sqlite-users mailing list 
sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users 
___ Gunter Hick Software Engineer 
Scientific Games International GmbH FN 157284 a, HG Wien Klitschgasse 2-4, 
A-1130 Vienna, Austria Tel: +43 1 80100 0 E-Mail: hick at scigames.at This 
communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your 
cooperation. ___ sqlite-users 
mailing list 

[sqlite] get blob colums values by sqlite3_get_table?

2015-12-15 Thread 王庆刚
int sqlite3_get_table(
  sqlite3 *db,  /* An open database */
  const char *zSql, /* SQL to be evaluated */
  char ***pazResult,/* Results of the query */
  int *pnRow,   /* Number of result rows written here */
  int *pnColumn,/* Number of result columns written here */
  char **pzErrmsg   /* Error msg written here */
);

could I get blob colums values by sqlite3_get_table?
The result of the sqlite3_get_table would be stored in parameter pazResult.



[sqlite] 回复: Why SQLITE_BUSY?

2015-12-15 Thread sanhua.zh
I?m very excited that I re-produce the SQLITE_BUSY code in a simple demo.
Here is my test code,


void showResultCode(int resultCode)
{
  if (resultCode!=SQLITE_DONEresultCode!=SQLITE_OKresultCode!=SQLITE_ROW) {
NSLog(@"unexperted result %d", resultCode);
  }
}


void SQLiteLog(void* userInfo, int ret, const char* msg)
{
  NSLog(@"ret=%d, msg=%s", ret, msg);
}


void write(const char* path)
{
  int code = SQLITE_OK;
  sqlite3* handle;


  showResultCode(sqlite3_open(path, handle));


  sqlite3_exec(handle, "PRAGMA journal_mode=WAL", nullptr, nullptr, nullptr);
  sqlite3_exec(handle, "create table test(id integer);", nullptr, nullptr, 
nullptr);


  sqlite3_stmt* stmt = nullptr;
  showResultCode(sqlite3_exec(handle, "BEGIN IMMEDIATE", nullptr, nullptr, 
nullptr));
  for (int i = 0; i  2; i++) {
showResultCode(sqlite3_prepare(handle, [NSString stringWithFormat:@"insert 
into test values(%d);", i].UTF8String, -1, stmt, nullptr));
showResultCode(sqlite3_step(stmt));
  }
  showResultCode(sqlite3_exec(handle, "COMMIT", nullptr, nullptr, nullptr));
  showResultCode(sqlite3_finalize(stmt));
  showResultCode(sqlite3_close(handle));
}


int main(int argc, char * argv[])
{
  sqlite3_config(SQLITE_CONFIG_LOG, SQLiteLog, NULL);


  const char* path = "/Users/sanhuazhang/Desktop/test.db";
  write(path);
  return 1;
}


The console result is ?unexperted result 5?, which indicates SQLITE_BUSY. It 
happens at code?sqlite3_close?.one of the strange things is that?SQLiteLog? 
print nothing.
AndYou can see that I only write some data using transaction. How could 
SQLITE_BUSY happened while sqlite.org said that?The SQLITE_BUSY result code 
indicates that the database file could not be written (or in some cases read) 
because of concurrent activity by some other database connection.?.


So, as a conclusion, I confuse that why the result code of?sqlite3_close" is 
SQLITE_BUSY and is it possible that SQLITE_BUSY returned by other function in 
this situation(single process,single thread,single connection).



???:sanhua.zhsanhua.zh at foxmail.com
???:sqlite-userssqlite-users at mailinglists.sqlite.org
:2015?12?14?(??)?17:21
??:[sqlite] Why SQLITE_BUSY?


I queue all my db operation into one thread with single sqlite conn. neither 
multi-thread nor multi-process operation happened.But some SQLITE_BUSY error 
code still be catched. I can not re-produce this error code indeveloping 
environment,because it happen in alow probability. I only catch this error 
report online. So how did it happen? I guess that, when WAL reach the 
checkpoint, sqlite will write the data back to original db file in background 
thread. So writing will be busy at this time. But I?m not sure. I hope that you 
will not stint your criticism ___ 
sqlite-users mailing list sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Richard Hipp
On 12/15/15, Karl Lehenbauer  wrote:
>
> sqlite> select fp from flightplans;
>
> Error: no such column: fp
>
> But if I select a column that doesn?t exist within an embedded subquery, it
> is not an error?
>
> sqlite> delete from inflight where fp in (select fp from flightplans);
>

The "fp" in the subquery resolves to the "inflight" table of the outer
query.  In other words, the subquery is acting like a correlated
subquery.  This is confusing, I know, but it is the Right Thing.
PosgreSQL does the same.

Interesting timing:  I was monitoring an inbound flight on flightaware
when this issue report arrived in my inbox.  :-)

-- 
D. Richard Hipp
drh at sqlite.org


[sqlite] Fastest read?

2015-12-15 Thread 王庆刚
hi,all
I want to improve the speed of the retrieve records.
I try so many methods. and find the result is not good. Such as retrieve by 
rowid, index and so on.
Is there any other method which can improve the retrieve speed?

Best regards.
 WQG


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
Thanks, nice and simple and helpful advice.

RBS
On 15 Dec 2015 1:45 pm, "Richard Hipp"  wrote:

> On 12/15/15, Bart Smissaert  wrote:
> > So I will need to use SQLITE_TRANSIENT then?
> >
>
> Yes.  Always use SQLITE_TRANSIENT, at least initially.  All the other
> options are optimizations.  Do not use the other options prematurely
> (that is to say, without first trying SQLITE_TRANSIENT and actually
> measuring that it presents performance problems) because premature
> optimization is the root of all evil
> (http://c2.com/cgi/wiki?PrematureOptimization).
> --
> D. Richard Hipp
> drh at sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] Is rowid the fastest?

2015-12-15 Thread 王庆刚





When it revert back after dropping the index. The speed does not become slower.


At 2015-12-14 21:35:03, "Hick Gunter"  wrote:
>Does it revert back to slower speed after dropping the index?
>Can you compare the EXPLAIN output produced with and without the index?
>
>There is no difference on my machine (Version 3.7.14); if yours behaves the 
>same way then whatever changes speed is definitely not because SQLite is doing 
>something differently.
>
>asql> create temp table t (x integer primary key asc, y,z);
>asql> .explain
>asql> explain select * from t where rowid=15;
>addr  opcode p1p2p3p4 p5  comment
>  -        -  --  -
>0 Trace  0 0 000  NULL
>1 Integer151 000  NULL
>2 Goto   0 12000  NULL
>3 OpenRead   0 2 1 3  00  t
>4 MustBeInt  1 10000  NULL
>5 NotExists  0 10100  pk
>6 Rowid  0 3 000  NULL
>7 Column 0 1 400  t.y
>8 Column 0 2 500  t.z
>9 ResultRow  3 3 000  NULL
>10Close  0 0 000  NULL
>11Halt   0 0 000  NULL
>12Transaction1 0 000  NULL
>13VerifyCookie   1 1 000  NULL
>14TableLock  1 2 0 t  00  NULL
>15Goto   0 3 000  NULL
>asql> explain select * from t where x=15;
>addr  opcode p1p2p3p4 p5  comment
>  -        -  --  -
>0 Trace  0 0 000  NULL
>1 Integer151 000  NULL
>2 Goto   0 12000  NULL
>3 OpenRead   0 2 1 3  00  t
>4 MustBeInt  1 10000  NULL
>5 NotExists  0 10100  pk
>6 Rowid  0 3 000  NULL
>7 Column 0 1 400  t.y
>8 Column 0 2 500  t.z
>9 ResultRow  3 3 000  NULL
>10Close  0 0 000  NULL
>11Halt   0 0 000  NULL
>12Transaction1 0 000  NULL
>13VerifyCookie   1 1 000  NULL
>14TableLock  1 2 0 t  00  NULL
>15Goto   0 3 000  NULL
>asql> create index t_x on t(x);
>asql> explain select * from t where x=15;
>addr  opcode p1p2p3p4 p5  comment
>  -        -  --  -
>0 Trace  0 0 000  NULL
>1 Integer151 000  NULL
>2 Goto   0 12000  NULL
>3 OpenRead   0 2 1 3  00  t
>4 MustBeInt  1 10000  NULL
>5 NotExists  0 10100  pk
>6 Rowid  0 3 000  NULL
>7 Column 0 1 400  t.y
>8 Column 0 2 500  t.z
>9 ResultRow  3 3 000  NULL
>10Close  0 0 000  NULL
>11Halt   0 0 000  NULL
>12Transaction1 0 000  NULL
>13VerifyCookie   1 2 000  NULL
>14TableLock  1 2 0 t  00  NULL
>15Goto   0 3 000  NULL
>
>-Urspr?ngliche Nachricht-
>Von: sqlite-users-bounces at mailinglists.sqlite.org 
>[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von ???
>Gesendet: Montag, 14. Dezember 2015 14:06
>An: SQLite mailing list
>Betreff: [sqlite] Is rowid the fastest?
>
>You said that "You are probably falling into the cache effect trap again. 
>There is no point in indexing on the primary key, it only wastes space and CPU 
>cycles ".
> I do not agree with you. let me tell you why.
> Before I retrieve by index which created for primary key. The speed of 
> retrieve by rowid is very stable(for a long time).
> Once I retrieve by index , the stable will broken and the speed is faster 
> than its before.
> I think you could try it.
>
>
>
>
>
>___
> Gunter Hick
>Software 

[sqlite] Problem when upgrading from FTS3/4toFTS5modules(revisited)

2015-12-15 Thread a...@zator.com

>
>  Mensaje original 
> De: Dan Kennedy 
> Para:  sqlite-users at mailinglists.sqlite.org
> Fecha:  Mon, 14 Dec 2015 19:15:23 +0700
> Asunto:  Re: [sqlite] Problem when upgrading from 
> FTS3/4toFTS5modules(revisited)
>
> 
>
>So that looks like database corruption, except we don't think the 
>database is actually corrupt as the DROP TABLE statement did not fail 
>when run in the shell tool. So perhaps heap-corruption has caused the 
>in-memory cache to become corrupt.
>
>Can you run the whole thing under valgrind?
>

Dan:

This is a Windows app build with MS Visual Studio C++, so can't use Valgrind.

Perhaps the cause is a heap corruption, but I doubt because the problem behaves 
consistently in the following scenarios:

a.- The problem appears only when the table is build with the FTS5 modules and 
not when using FTS3/4.
b.- The problem appears when calling the query in different points in the code.
c.- The problem appears in both: debug mode and release mode.
d.- The code behaves correctly changing the name of the table (deletes 
successfully any other table).

I'm pending to tests the same whith other System version in the same equipe 
(actually using Windows 10 with AMD 64 bits, but can boot the same with Window 
7).

Any way I managed a workaround with a fakeDelete function with this logic:

Detect if the table ftsm exist:

Not exist:
   -> Create and populate the table.

Exists
   -> "DELETE FROM ftsm WHERE nm IS NOT null" (hope this erase all files)
   -> "VACUUM ftsm"
   -> Populate the table

Cheers.

--
Adolfo J. Millan




[sqlite] get blob colums values by sqlite3_get_table?

2015-12-15 Thread Clemens Ladisch
??? wrote:
> int sqlite3_get_table(
>   char ***pazResult,/* Results of the query */
>
> could I get blob colums values by sqlite3_get_table?

Yes.  But like any other values, they are converted to strings.


Regards,
Clemens


[sqlite] Bug: sqlite ships with old autotools

2015-12-15 Thread Jeroen Demeyer
Dear SQLite developers,

The newest released version 3.9.2 of sqlite-autotools ships with an old 
version of autotools. In particular, it fails to compile on this system:

$ uname -a
Linux sardonis 3.19.0-15-generic #15-Ubuntu SMP Thu Apr 16 23:32:13 UTC 
2015 ppc64le ppc64le ppc64le GNU/Linux

with this error from ./configure:

UNAME_MACHINE = ppc64le
UNAME_RELEASE = 3.19.0-15-generic
UNAME_SYSTEM  = Linux
UNAME_VERSION = #15-Ubuntu SMP Thu Apr 16 23:32:13 UTC 2015
configure: error: cannot guess build type; you must specify one


This problem can be solved by re-autotoolizing with up-to-date 
autotools. The build on ppc64le succeeds after doing that.


Jeroen Demeyer.


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
> I have no idea how VB6 implements local variables

Pure local variables (declared in the actual procedure) are on the stack as
well in VB6.
VB6 hides all these kind of details, so I never think about this/deal with
this.

RBS

On Tue, Dec 15, 2015 at 9:33 AM, Hick Gunter  wrote:

> >Thanks for clarifying that.
> >
> >> If the pointer refers to memory obtained from sqlite3_malloc
> >How do I know that is the case?
> >My callback procedure (the procedure that does the actual work, altering
> the string) is in a VB6 ActiveX dll, so not in sqlite3.dll
>
> If you called an sqlite3 API function that says it allocates memory, like
> sqlite3_malloc() or sqlite3_mprinft() to produce the string.
>
> >
> >> If the pointer refers to memory obtained from your own allocator
> >I suppose this is the case if it is a local variable in this callback
> procedure in my VB6 dll.
> >In VB6 local variables will go out of scope (cleaned up) once the
> procedure is finished.
> >So in that case can I use SQLITE_STATIC?
>
> I guess NO. SQLite needs the value until at least up to the next call to
> sqlite3_step(). Calling sqlite3_finalize() or sqlite3_reset() should also
> "clear" the "current row".
>
>
> >
> >> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
> >> of the memory appropriately.
> >When is it necessary and what is appropriate?
>
> You should know where the memory used to store the string in your own code
> comes from and how to deal with it.
>
> As you already stated, a local variable in your callback procedure goes
> out of scope automatically. I have no idea how VB6 implements local
> variables; in C they are located on the stack, which may be overwritten by
> other function calls.
>
>
> On Tue, Dec 15, 2015 at 7:52 AM, Hick Gunter  wrote:
>
> >> The rules are quite simple:
> >>
> >> If the pointer refers to static memory (preallocated string constants,
> >> global variables that you can guarantee won't change while SQLite uses
> >> them) use SQLITE_STATIC
> >>
> >> If the pointer refers to memory obtained from sqlite3_malloc (directly
> >> or indirectly e.g. via sqlite3_mprintf() ) and you won't refer to this
> >> object again, pass sqlite3_free.
> >>
> >> If the pointer refers to memory obtained from your own allocator and
> >> you won't refer to this object again, pass your own destructor.
> >>
> >> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
> >> of the memory appropriately.
> >>
> >> SQLITE_TRANSIENT is safe but slow, because SQLite needs to copy the
> string.
> >> Passing a destructor function is faster but implies a contract to NOT
> >> USE THE POINTER AGAIN yourself.
> >> SQLITE_STATIC is fastest but implies a contract that the MEMORY WILL
> >> NOT CHANGE.
> >>
>
>
> ___
>  Gunter Hick
> Software Engineer
> Scientific Games International GmbH
> FN 157284 a, HG Wien
> Klitschgasse 2-4, A-1130 Vienna, Austria
> Tel: +43 1 80100 0
> E-Mail: hick at scigames.at
>
> This communication (including any attachments) is intended for the use of
> the intended recipient(s) only and may contain information that is
> confidential, privileged or legally protected. Any unauthorized use or
> dissemination of this communication is strictly prohibited. If you have
> received this communication in error, please immediately notify the sender
> by return e-mail message and delete all copies of the original
> communication. Thank you for your cooperation.
>
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
> If you are saying that you plan to obtain the character pointer by
calling sqlite3_value_text, then pass that exact pointer to
sqlite3_result_text, then I would suggest you use sqlite3_result_value
instead

But sqlite3_result_value has no option to only set the first X bytes, so it
won't allow me to retain only part of the string.
Or is there a way to do this with sqlite3_result_value?

RBS

On Mon, Dec 14, 2015 at 9:00 PM, Igor Tandetnik  wrote:

> On 12/14/2015 3:09 PM, Bart Smissaert wrote:
>
>> It could be either a pointer to sqlite3_value_text of sqlite3_value*
>>
>
> No it can't be. sqlite3_result_text takes a char*, not a sqlite3_value* or
> a const unsigned char*(*)(sqlite3_value*)
>
> If you are saying that you plan to obtain the character pointer by calling
> sqlite3_value_text, then pass that exact pointer to sqlite3_result_text,
> then I would suggest you use sqlite3_result_value instead: it takes
> sqlite3_value* directly. If you insist on round-tripping through
> sqlite3_value_text, then you must pass SQLITE_TRANSIENT for the last
> parameter - the pointer returned by sqlite3_value_text is only guaranteed
> to be valid until the custom function returns.
>
> or it could be a pointer to a locally declared variable
>>
>
> In this case, you would also use SQLITE_TRANSIENT.
>
> --
> Igor Tandetnik
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] Fastest read?

2015-12-15 Thread Simon Slavin

> On 15 Dec 2015, at 7:18am, ??? <2004wqg2008 at 163.com> wrote:
> 
>I want to improve the speed of the retrieve records.
>I try so many methods. and find the result is not good. Such as retrieve 
> by rowid, index and so on.
>Is there any other method which can improve the retrieve speed?

What is your SELECT command ?

What is your table definition ?

Simon.


[sqlite] SELECT CAST('' AS INTEGER) returns zero instead of null

2015-12-15 Thread Simon Slavin

On 14 Dec 2015, at 2:26pm, Anthony Damico  wrote:

> hi, sql standard says to strip whitespace and then convert.  "" coercing to
> zero instead of NULL strikes me as very odd..  thanks

In your command

SELECT CAST('' AS INTEGER)

you explicitly tell it to

CAST('' AS INTEGER)

which means it has to return an integer.  The integer most like a zero-length 
string is zero.  NULL is a different type of value.

In SQL a zero-length string has nothing to do with NULL.  A zero-length string 
is just another string.  NULL means something like "value missing" or "value 
unknown" or "no such value".  SQLite never confuses the two.

Simon.


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
> like sqlite3_malloc() or sqlite3_mprinft() to produce the string.
OK, I won't be doing that.

> I guess NO
So I will need to use SQLITE_TRANSIENT then?

> You should know where the memory used to store the string in your own
code comes from and how to deal with it.
It will nearly always be a local variable, unless I can avoid this copy and
use sqlite3_result_value directly as suggested
by Igor. This would be better as it should speed matters up. Not tried this
yet.

RBS

On Tue, Dec 15, 2015 at 9:33 AM, Hick Gunter  wrote:

> >Thanks for clarifying that.
> >
> >> If the pointer refers to memory obtained from sqlite3_malloc
> >How do I know that is the case?
> >My callback procedure (the procedure that does the actual work, altering
> the string) is in a VB6 ActiveX dll, so not in sqlite3.dll
>
> If you called an sqlite3 API function that says it allocates memory, like
> sqlite3_malloc() or sqlite3_mprinft() to produce the string.
>
> >
> >> If the pointer refers to memory obtained from your own allocator
> >I suppose this is the case if it is a local variable in this callback
> procedure in my VB6 dll.
> >In VB6 local variables will go out of scope (cleaned up) once the
> procedure is finished.
> >So in that case can I use SQLITE_STATIC?
>
> I guess NO. SQLite needs the value until at least up to the next call to
> sqlite3_step(). Calling sqlite3_finalize() or sqlite3_reset() should also
> "clear" the "current row".
>
>
> >
> >> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
> >> of the memory appropriately.
> >When is it necessary and what is appropriate?
>
> You should know where the memory used to store the string in your own code
> comes from and how to deal with it.
>
> As you already stated, a local variable in your callback procedure goes
> out of scope automatically. I have no idea how VB6 implements local
> variables; in C they are located on the stack, which may be overwritten by
> other function calls.
>
>
> On Tue, Dec 15, 2015 at 7:52 AM, Hick Gunter  wrote:
>
> >> The rules are quite simple:
> >>
> >> If the pointer refers to static memory (preallocated string constants,
> >> global variables that you can guarantee won't change while SQLite uses
> >> them) use SQLITE_STATIC
> >>
> >> If the pointer refers to memory obtained from sqlite3_malloc (directly
> >> or indirectly e.g. via sqlite3_mprintf() ) and you won't refer to this
> >> object again, pass sqlite3_free.
> >>
> >> If the pointer refers to memory obtained from your own allocator and
> >> you won't refer to this object again, pass your own destructor.
> >>
> >> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
> >> of the memory appropriately.
> >>
> >> SQLITE_TRANSIENT is safe but slow, because SQLite needs to copy the
> string.
> >> Passing a destructor function is faster but implies a contract to NOT
> >> USE THE POINTER AGAIN yourself.
> >> SQLITE_STATIC is fastest but implies a contract that the MEMORY WILL
> >> NOT CHANGE.
> >>
>
>
> ___
>  Gunter Hick
> Software Engineer
> Scientific Games International GmbH
> FN 157284 a, HG Wien
> Klitschgasse 2-4, A-1130 Vienna, Austria
> Tel: +43 1 80100 0
> E-Mail: hick at scigames.at
>
> This communication (including any attachments) is intended for the use of
> the intended recipient(s) only and may contain information that is
> confidential, privileged or legally protected. Any unauthorized use or
> dissemination of this communication is strictly prohibited. If you have
> received this communication in error, please immediately notify the sender
> by return e-mail message and delete all copies of the original
> communication. Thank you for your cooperation.
>
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] [RE] System.Data.SQLite version 1.0.99.0 released

2015-12-15 Thread Zaumseil René
Hello

I have still problems to get it working on SQL Server2012 R2.
I got the following message:
"That assembly does not allow partially trusted"

The server is shared and there is no possibility to change system settings.
The program uses ASP.NET C# library under IIS.

Is there a possibility to change the trust level?
Or is there a package with another trust level?

Thank you
Ren? Zaumseil


Kernkraftwerk Goesgen-Daeniken AG
CH-4658 Daeniken, Switzerland

Diese Nachricht (inkl. Anhaenge) beinhaltet moeglicherweise vertrauliche oder 
gesetzlich geschuetzte Daten oder Informationen. Zum Empfang derselben ist 
(sind) ausschliesslich die genannte(n) Person(en) bestimmt. Falls Sie diese 
Nachricht irrtuemlicherweise erreicht hat, sind Sie hoeflich gebeten, diese 
unter Ausschluss jeder Reproduktion zu vernichten und den Absender umgehend zu 
benachrichtigen. Besten Dank.


[sqlite] 回复: Why SQLITE_BUSY?

2015-12-15 Thread Hick Gunter
It looks like you have unfinalized statements in your transaction. You are 
preparing statements inside the loop, but finalizing only 1 (the last) 
statement. And attempting to commit even before finalizing only the last 
statement. So sqlite3_close() is complaining about improper call sequence, not 
interference from any other process/thread.

-Urspr?ngliche Nachricht-
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von 
sanhua.zh
Gesendet: Dienstag, 15. Dezember 2015 10:27
An: SQLite mailing list
Betreff: [sqlite] ??? Why SQLITE_BUSY?

I?m very excited that I re-produce the SQLITE_BUSY code in a simple demo.
Here is my test code,


void showResultCode(int resultCode)
{
  if (resultCode!=SQLITE_DONEresultCode!=SQLITE_OKresultCode!=SQLITE_ROW) {
NSLog(@"unexperted result %d", resultCode);
  }
}


void SQLiteLog(void* userInfo, int ret, const char* msg) {
  NSLog(@"ret=%d, msg=%s", ret, msg);
}


void write(const char* path)
{
  int code = SQLITE_OK;
  sqlite3* handle;


  showResultCode(sqlite3_open(path, handle));


  sqlite3_exec(handle, "PRAGMA journal_mode=WAL", nullptr, nullptr, nullptr);
  sqlite3_exec(handle, "create table test(id integer);", nullptr, nullptr, 
nullptr);


  sqlite3_stmt* stmt = nullptr;
  showResultCode(sqlite3_exec(handle, "BEGIN IMMEDIATE", nullptr, nullptr, 
nullptr));
  for (int i = 0; i  2; i++) {
showResultCode(sqlite3_prepare(handle, [NSString stringWithFormat:@"insert 
into test values(%d);", i].UTF8String, -1, stmt, nullptr));
showResultCode(sqlite3_step(stmt));
  }
  showResultCode(sqlite3_exec(handle, "COMMIT", nullptr, nullptr, nullptr));
  showResultCode(sqlite3_finalize(stmt));
  showResultCode(sqlite3_close(handle));
}


int main(int argc, char * argv[])
{
  sqlite3_config(SQLITE_CONFIG_LOG, SQLiteLog, NULL);


  const char* path = "/Users/sanhuazhang/Desktop/test.db";
  write(path);
  return 1;
}


The console result is ?unexperted result 5?, which indicates SQLITE_BUSY. It 
happens at code?sqlite3_close?.one of the strange things is that?SQLiteLog? 
print nothing.
AndYou can see that I only write some data using transaction. How could 
SQLITE_BUSY happened while sqlite.org said that?The SQLITE_BUSY result code 
indicates that the database file could not be written (or in some cases read) 
because of concurrent activity by some other database connection.?.


So, as a conclusion, I confuse that why the result code of?sqlite3_close" is 
SQLITE_BUSY and is it possible that SQLITE_BUSY returned by other function in 
this situation(single process,single thread,single connection).



???:sanhua.zhsanhua.zh at foxmail.com
???:sqlite-userssqlite-users at mailinglists.sqlite.org
:2015?12?14?(??)?17:21
??:[sqlite] Why SQLITE_BUSY?


I queue all my db operation into one thread with single sqlite conn. neither 
multi-thread nor multi-process operation happened.But some SQLITE_BUSY error 
code still be catched. I can not re-produce this error code indeveloping 
environment,because it happen in alow probability. I only catch this error 
report online. So how did it happen? I guess that, when WAL reach the 
checkpoint, sqlite will write the data back to original db file in background 
thread. So writing will be busy at this time. But I?m not sure. I hope that you 
will not stint your criticism ___ 
sqlite-users mailing list sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users at mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: hick at scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.




[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Hick Gunter
>Thanks for clarifying that.
>
>> If the pointer refers to memory obtained from sqlite3_malloc
>How do I know that is the case?
>My callback procedure (the procedure that does the actual work, altering the 
>string) is in a VB6 ActiveX dll, so not in sqlite3.dll

If you called an sqlite3 API function that says it allocates memory, like 
sqlite3_malloc() or sqlite3_mprinft() to produce the string.

>
>> If the pointer refers to memory obtained from your own allocator
>I suppose this is the case if it is a local variable in this callback 
>procedure in my VB6 dll.
>In VB6 local variables will go out of scope (cleaned up) once the procedure is 
>finished.
>So in that case can I use SQLITE_STATIC?

I guess NO. SQLite needs the value until at least up to the next call to 
sqlite3_step(). Calling sqlite3_finalize() or sqlite3_reset() should also 
"clear" the "current row".


>
>> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
>> of the memory appropriately.
>When is it necessary and what is appropriate?

You should know where the memory used to store the string in your own code 
comes from and how to deal with it.

As you already stated, a local variable in your callback procedure goes out of 
scope automatically. I have no idea how VB6 implements local variables; in C 
they are located on the stack, which may be overwritten by other function calls.


On Tue, Dec 15, 2015 at 7:52 AM, Hick Gunter  wrote:

>> The rules are quite simple:
>>
>> If the pointer refers to static memory (preallocated string constants,
>> global variables that you can guarantee won't change while SQLite uses
>> them) use SQLITE_STATIC
>>
>> If the pointer refers to memory obtained from sqlite3_malloc (directly
>> or indirectly e.g. via sqlite3_mprintf() ) and you won't refer to this
>> object again, pass sqlite3_free.
>>
>> If the pointer refers to memory obtained from your own allocator and
>> you won't refer to this object again, pass your own destructor.
>>
>> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose
>> of the memory appropriately.
>>
>> SQLITE_TRANSIENT is safe but slow, because SQLite needs to copy the string.
>> Passing a destructor function is faster but implies a contract to NOT
>> USE THE POINTER AGAIN yourself.
>> SQLITE_STATIC is fastest but implies a contract that the MEMORY WILL
>> NOT CHANGE.
>>


___
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: hick at scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.




[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
Thanks for clarifying that.

> If the pointer refers to memory obtained from sqlite3_malloc
How do I know that is the case?
My callback procedure (the procedure that does the actual work, altering
the string) is in a VB6 ActiveX dll,
so not in sqlite3.dll

> If the pointer refers to memory obtained from your own allocator
I suppose this is the case if it is a local variable in this callback
procedure in my VB6 dll.
In VB6 local variables will go out of scope (cleaned up) once the procedure
is finished.
So in that case can I use SQLITE_STATIC?

> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose of
the memory appropriately.
When is it necessary and what is appropriate?

RBS





On Tue, Dec 15, 2015 at 7:52 AM, Hick Gunter  wrote:

> The rules are quite simple:
>
> If the pointer refers to static memory (preallocated string constants,
> global variables that you can guarantee won't change while SQLite uses
> them) use SQLITE_STATIC
>
> If the pointer refers to memory obtained from sqlite3_malloc (directly or
> indirectly e.g. via sqlite3_mprintf() ) and you won't refer to this object
> again, pass sqlite3_free.
>
> If the pointer refers to memory obtained from your own allocator and you
> won't refer to this object again, pass your own destructor.
>
> In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose of
> the memory appropriately.
>
> SQLITE_TRANSIENT is safe but slow, because SQLite needs to copy the string.
> Passing a destructor function is faster but implies a contract to NOT USE
> THE POINTER AGAIN yourself.
> SQLITE_STATIC is fastest but implies a contract that the MEMORY WILL NOT
> CHANGE.
>
> -Urspr?ngliche Nachricht-
> Von: sqlite-users-bounces at mailinglists.sqlite.org [mailto:
> sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von Bart
> Smissaert
> Gesendet: Montag, 14. Dezember 2015 20:22
> An: General Discussion of SQLite Database
> Betreff: [sqlite] sqlite3_free needed when calling sqlite3_result_text ?
>
> Not sure if I need to call sqlite3_free after running sqlite3_result_text
> or if sqlite3_free should be an argument  (last one) in sqlite3_result_text.
> Currently I am using SQLITE_TRANSIENT as the last argument, so that is
> after the number of bytes, but have feeling I might be doing this wrong.
> Thanks for any advice.
>
> RBS
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
> ___
>  Gunter Hick
> Software Engineer
> Scientific Games International GmbH
> FN 157284 a, HG Wien
> Klitschgasse 2-4, A-1130 Vienna, Austria
> Tel: +43 1 80100 0
> E-Mail: hick at scigames.at
>
> This communication (including any attachments) is intended for the use of
> the intended recipient(s) only and may contain information that is
> confidential, privileged or legally protected. Any unauthorized use or
> dissemination of this communication is strictly prohibited. If you have
> received this communication in error, please immediately notify the sender
> by return e-mail message and delete all copies of the original
> communication. Thank you for your cooperation.
>
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
>  but the string "abc" is not 4 bytes long, no matter how you count.

Yes, sorry to cause confusion there, the -2 got in there as in my testing
setup there was always a space before the string to find. This is not
really to do with the problem I am seeing though.

RBS




On Tue, Dec 15, 2015 at 1:22 AM, Igor Tandetnik  wrote:

> On 12/14/2015 7:42 PM, Bart Smissaert wrote:
>
>> Yes, str and str2 are Unicode string, 2 bytes per character.
>> lPos counts per character, not byte, so if the string in the database is
>> abcde and I want to find the first position
>> of d in that string then lPos will be 4.
>>
>
> ... and then you pass (lPos-2)*2 == 4 - but the string "abc" is not 4
> bytes long, no matter how you count.
>
> You are converting in one direction (SQLite to VB), but not in the other
>>>
>> I thought SQLite would handle VB Unicode strings to UTF8 strings
>>
>
> It would, if you use the correct API function, so that SQLite knows that
> the string is in fact Unicode.
>
> --
> Igor Tandetnik
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Richard Hipp
On 12/15/15, Bart Smissaert  wrote:
> So I will need to use SQLITE_TRANSIENT then?
>

Yes.  Always use SQLITE_TRANSIENT, at least initially.  All the other
options are optimizations.  Do not use the other options prematurely
(that is to say, without first trying SQLITE_TRANSIENT and actually
measuring that it presents performance problems) because premature
optimization is the root of all evil
(http://c2.com/cgi/wiki?PrematureOptimization).
-- 
D. Richard Hipp
drh at sqlite.org


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Hick Gunter
The rules are quite simple:

If the pointer refers to static memory (preallocated string constants, global 
variables that you can guarantee won't change while SQLite uses them) use 
SQLITE_STATIC

If the pointer refers to memory obtained from sqlite3_malloc (directly or 
indirectly e.g. via sqlite3_mprintf() ) and you won't refer to this object 
again, pass sqlite3_free.

If the pointer refers to memory obtained from your own allocator and you won't 
refer to this object again, pass your own destructor.

In all other cases, pass SQLITE_TRANSIENT and, if necessary, dispose of the 
memory appropriately.

SQLITE_TRANSIENT is safe but slow, because SQLite needs to copy the string.
Passing a destructor function is faster but implies a contract to NOT USE THE 
POINTER AGAIN yourself.
SQLITE_STATIC is fastest but implies a contract that the MEMORY WILL NOT CHANGE.

-Urspr?ngliche Nachricht-
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von Bart 
Smissaert
Gesendet: Montag, 14. Dezember 2015 20:22
An: General Discussion of SQLite Database
Betreff: [sqlite] sqlite3_free needed when calling sqlite3_result_text ?

Not sure if I need to call sqlite3_free after running sqlite3_result_text or if 
sqlite3_free should be an argument  (last one) in sqlite3_result_text.
Currently I am using SQLITE_TRANSIENT as the last argument, so that is after 
the number of bytes, but have feeling I might be doing this wrong.
Thanks for any advice.

RBS
___
sqlite-users mailing list
sqlite-users at mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: hick at scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.




[sqlite] Locked database

2015-12-15 Thread Cecil Westerhof
2015-12-14 15:14 GMT+01:00 Clemens Ladisch :

> Cecil Westerhof wrote:
> > sqlite3 "${DATABASE}" "begin immediate" 2>/dev/null
> > errorCode="${?}"
> > if [[ "${errorCode}" -eq 5 ]] ; then
> > printf "${DATABASE} is locked\n"
> >
> > I saw that when it is locked I get back a 5. Is this always the case?
>
> sqlite3 returns the SQLite error code, and 5 indeed is SQLITE_BUSY.
> (Non-SQL errors result in 1, which would be the same as SQLITE_ERROR.)
>

?And here are the other codes; ;-)
https://sqlite.org/c3ref/c_abort.html?


-- 
Cecil Westerhof


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
Maybe I shouldn't  make Unicode strings but keep it all in UTF8.
Not sure though how to get the position then of string2 in string1, lPos.

RBS



On Tue, Dec 15, 2015 at 12:42 AM, Bart Smissaert 
wrote:

> Yes, str and str2 are Unicode string, 2 bytes per character.
> lPos counts per character, not byte, so if the string in the database is
> abcde and I want to find the first position
> of d in that string then lPos will be 4.
>
> > You are converting in one direction (SQLite to VB), but not in the other
> I thought SQLite would handle VB Unicode strings to UTF8 strings, but I
> think you may be onto something there,
> because if I move VB Unicode strings to SQLite I do sqlite3_bind_text16
> and I understand sqlite3_result_text is very
> similar to sqlite3_bind_text. So, it makes sense I need
> sqlite3_result_text16 instead.
>
> Will do some further testing.
>
> RBS
>
>
>
>
> On Tue, Dec 15, 2015 at 12:22 AM, Igor Tandetnik 
> wrote:
>
>> On 12/14/2015 5:46 PM, Bart Smissaert wrote:
>>
>>> OK, thanks, will have to study this carefully.
>>> So, if I understand you well then the way I do it now I would need
>>> sqlite3_free?
>>>
>>
>> First, I don't know how you do it now - you've never described that.
>> Second, I have not ever said you needed sqlite3_free; nothing in your
>> description of the problem so far suggests you need it.
>>
>>  'string not found, so return original field string
>>>  '-
>>> 140 If lPos = 0 Then
>>> 150   sqlite3_result_value lPtr_ObjContext, lPtr1
>>> 160   Exit Sub
>>> 170 End If
>>> 180 sqlite3_result_text lPtr_ObjContext, StrPtr(str), _
>>> (lPos - 2) * 2, SQLITE_TRANSIENT
>>>
>>
>> To the extent I understand what's going on (I'm not really familiar with
>> VB, so I'm taking and educated guess for the most part), the memory
>> management part looks OK to me.
>>
>> However, I have doubts about encoding. Comments seem to suggest str
>> points to a Unicode string; also the fact that you multiply lPos by 2. But
>> sqlite3_result_text expects UTF-8 string. You are converting in one
>> direction (SQLite to VB), but not in the other, as far as I can tell. I
>> suspect you need sqlite3_result_text16 instead.
>>
>> Also lPos-2 looks wrong. Can't the substring be found at lPos == 1 ?
>>
>> --
>> Igor Tandetnik
>>
>> ___
>> sqlite-users mailing list
>> sqlite-users at mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>>
>
>


[sqlite] sqlite3_free needed when calling sqlite3_result_text ?

2015-12-15 Thread Bart Smissaert
Yes, str and str2 are Unicode string, 2 bytes per character.
lPos counts per character, not byte, so if the string in the database is
abcde and I want to find the first position
of d in that string then lPos will be 4.

> You are converting in one direction (SQLite to VB), but not in the other
I thought SQLite would handle VB Unicode strings to UTF8 strings, but I
think you may be onto something there,
because if I move VB Unicode strings to SQLite I do sqlite3_bind_text16 and
I understand sqlite3_result_text is very
similar to sqlite3_bind_text. So, it makes sense I need
sqlite3_result_text16 instead.

Will do some further testing.

RBS




On Tue, Dec 15, 2015 at 12:22 AM, Igor Tandetnik  wrote:

> On 12/14/2015 5:46 PM, Bart Smissaert wrote:
>
>> OK, thanks, will have to study this carefully.
>> So, if I understand you well then the way I do it now I would need
>> sqlite3_free?
>>
>
> First, I don't know how you do it now - you've never described that.
> Second, I have not ever said you needed sqlite3_free; nothing in your
> description of the problem so far suggests you need it.
>
>  'string not found, so return original field string
>>  '-
>> 140 If lPos = 0 Then
>> 150   sqlite3_result_value lPtr_ObjContext, lPtr1
>> 160   Exit Sub
>> 170 End If
>> 180 sqlite3_result_text lPtr_ObjContext, StrPtr(str), _
>> (lPos - 2) * 2, SQLITE_TRANSIENT
>>
>
> To the extent I understand what's going on (I'm not really familiar with
> VB, so I'm taking and educated guess for the most part), the memory
> management part looks OK to me.
>
> However, I have doubts about encoding. Comments seem to suggest str points
> to a Unicode string; also the fact that you multiply lPos by 2. But
> sqlite3_result_text expects UTF-8 string. You are converting in one
> direction (SQLite to VB), but not in the other, as far as I can tell. I
> suspect you need sqlite3_result_text16 instead.
>
> Also lPos-2 looks wrong. Can't the substring be found at lPos == 1 ?
>
> --
> Igor Tandetnik
>
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>