Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Martin Sigwald wrote:
 Here is the actual code:
 
 int main(void)
 {
 sqlite3* db_handle;
 
  sqlite3_open(DB_NAME,db_handle);
  sqlite3_close(db_handle);
  my_ping(10.0.0.4);
 
   return 0;
 }
 
 If I call close after ping, it works. However, if besides of opening the DB
 I perform any query, ping doesnt work either.

My best guess is that you are making an error with file descriptors.  It
can be quite easy to accidentally use various values with low numbers
instead of the actual file descriptor numbers, and you'll get away with
it until some other code (eg sqlite) opens and closes files.  (Note that
under some circumstances SQLite can leave file descriptors open even
after close is called.)

I suggest using strace and carefully examining the file descriptors used.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkupxGUACgkQmOOfHg372QTd2ACeNaCEFII4TuVK8ZtTpCvZeFeX
ivYAnjuLh8uKl1z1jVauy9Fxa60Po9RR
=AVyR
-END PGP SIGNATURE-
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] fast acces to one memory located table from two threads

2010-03-24 Thread Max Vlasov
 I need an application consisting two threads.
 In one of them i need to store incomming messages (one message is 1 to 8
 bytes of data) to temporary table existing only in memory.
 It needs to be fast, storing hundreds of messages per second.
 There i have a trigger deleting old rows and creating some sort of circular
 buffer.
 In separate thread there should be done some selects (read only) on this
 table
 sorting the informations and storing them into separate table(s) located on
 disk (jffs2 filesystem).


Are you talking about two processes? If not, why these two threads have to
have separated connections? If it's not necessary, I'd opened disk db,
attach memory database to it (see http://www.sqlite.org/inmemorydb.html )
and pass this db handle to both threads. One of them in this case will use
only memory part of the base (fast appending), another one will do necessary
selects and inserts to disk db part. After the db is closed, you will only
have disk part left. I don't know more about locking logic in this case,
because for performance reasons, it would be better for example, if memory
part only locked its part not affecting the disk part.

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


Re: [sqlite] fast acces to one memory located table from two threads

2010-03-24 Thread Jakub Ladman
One process, two threads.
I have found in documentation, that is not recommended to pass one connection 
from one thread to second one.

A partial succes, relative fast function, is proven with database file stored 
in ramdisk.
Hard disk file storage 16 inserts per second.
Ramdisk file storage 150 inserts per second.
Temporary table in ram 1500 inserts per second.

I have tried the one shared connection before i found the part in doc, that 
not recommends it, but there was some problems with locking in one 
configuration and segment violation in the second case.

Jakub Ladman
 Are you talking about two processes? If not, why these two threads have to
 have separated connections? If it's not necessary, I'd opened disk db,
 attach memory database to it (see http://www.sqlite.org/inmemorydb.html )
 and pass this db handle to both threads. One of them in this case will use
 only memory part of the base (fast appending), another one will do
  necessary selects and inserts to disk db part. After the db is closed, you
  will only have disk part left. I don't know more about locking logic in
  this case, because for performance reasons, it would be better for
  example, if memory part only locked its part not affecting the disk part.
 
 Max
 ___
 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] fast acces to one memory located table from two threads

2010-03-24 Thread Max Vlasov
One process, two threads.
 I have found in documentation, that is not recommended to pass one
 connection
 from one thread to second one.


Yes, you're right, forgot about this, only exception is sqlite3_interrupt
that can be called from other thread otherwise its existence makes no sense.
But you probably can work around this with your own mutexes, wrapping your
calls in the corresponding access/release calls, but I suppose there still
could exist some complexities. I didn't try it myself, but I guess there are
some operations that can be implemented safely with this approach.

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


[sqlite] Update problem in use C/C++ interface

2010-03-24 Thread 王志刚
Hi, I meet a problem in use c/c++ API to update a row in table.
all return value means the operate is successful, But the row have no
change at all.
and the INSERT , SELECT operation is OK.

I think maybe I'm not first one meet this problem.But I can't visit
the archive. So if anyone
here know about this problem,please help me.

the main code al follow:

wstring sql = LUPDATE Mail SET [Content] = ?1 [CurrentSize] = ?2
WHERE [MailID] = ?3;;

sqlite3_stmt *pstmt = NULL;
const char *pzTail = 0;
int nRes = SQLITE_OK;
nRes = sqlite3_prepare16_v2((sqlite3*)pDB, (void**)sql.c_str(),
sizeof(wchar_t) * sql.length(), pstmt, 0);
if (0 != nRes)
{
return -1;
}
do
{
int len = 0;
void* pdata = NULL;

//Content
pdata = (void*)pMail-m_content.c_str();
len = sizeof(wchar_t) * pMail-m_content.length();
if( SQLITE_OK != (nRes = sqlite3_bind_text16(pstmt, 1, pdata,
len, SQLITE_TRANSIENT)) )break;
//CurrentSize
if( SQLITE_OK != (nRes = sqlite3_bind_int(pstmt, 2,
pMail-m_curSize)) )break;
if( SQLITE_OK != (nRes = sqlite3_bind_int(pstmt, 3,
pMail-GetID())) )break;

if ( SQLITE_DONE != (nRes = sqlite3_step(pstmt)) ) break;
}while (0);

sqlite3_finalize(pstmt);
if(SQLITE_OK != nRes  SQLITE_DONE != nRes)
{
return -1;
}
else
{
return 0;
}


-- 
-- 
 Thanks!
王志刚
---
电话:021-62672000-2852
上海圣诺网络技术有限公司
---
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Update problem in use C/C++ interface

2010-03-24 Thread Igor Tandetnik
王志刚 wrote:
 Hi, I meet a problem in use c/c++ API to update a row in table.
 all return value means the operate is successful, But the row have no
 change at all.

How do you determine this?

 the main code al follow:
 
wstring sql = LUPDATE Mail SET [Content] = ?1 [CurrentSize] = ?2
 WHERE [MailID] = ?3;;

There should be a comma after ?1.

Are you sure there actually exists a record with the ID you bind for the third 
parameter? Note that, if there isn't, you won't get any errors - the statement 
simply won't update any rows.

sqlite3_stmt *pstmt = NULL;
const char *pzTail = 0;
int nRes = SQLITE_OK;
nRes = sqlite3_prepare16_v2((sqlite3*)pDB, (void**)sql.c_str(),
 sizeof(wchar_t) * sql.length(), pstmt, 0);

Why do you need to cast pDB? What type is it declared with?

The second parameter of sqlite3_prepare16_v2 is const void*, not void**. Your 
cast looks strange, though harmless. You shouldn't need any cast at all.
-- 
Igor Tandetnik

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


Re: [sqlite] sqlite 3.6.23 may cause memory overrun problem

2010-03-24 Thread D. Richard Hipp

On Mar 24, 2010, at 7:11 AM, Daniel Lin wrote:

 About this bug, I found change the code to following will let it  
 workable.
 But, I require your confirm.

 memcpy(pKeyInfo, zP4, sizeof(*pKeyInfo));

The SQLite code is correct as written.  Your change will cause SQLite  
to malfunction.

Check-in http://www.sqlite.org/src/ci/be27897991 is an attempt to  
suppress the warning from code guard.  But as I have no way of testing  
to see if the change obtained that goal.



 On Wed, Mar 24, 2010 at 19:04, Daniel Lin dlin...@gmail.com wrote:
 Dear Dr.,

 I use Borland C++ Builder with code guard checking function enabled  
 mode . (on 32 bits Windows XP)

 I found in an amalgamation sqlite.c may cause memory overrun.

 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const  
 char *zP4, int n){
 ...
 pOp-p4.pKeyInfo = pKeyInfo;
 if (pKeyInfo ){
   u8 *aSortOrder;
   memcpy(pKeyInfo, zP4, nByte);   /* this line force copy 17  
 bytes from 16 bytes structure */
   aSortOrder = pKeyInfo-aSortOrder;
   if( aSortOrder ){
 pKeyInfo-aSortOrder = (unsigned char*)pKeyInfo- 
 aColl[nField];
 memcpy(pKeyInfo-aSortOrder, aSortOrder, nField);
   }
   pOp-p4type = P4_KEYINFO;


D. Richard Hipp
d...@hwaci.com



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


[sqlite] regression in FTS3 offsets function in 3.6.23

2010-03-24 Thread Andrew Sutherland


As reported on https://bugzilla.mozilla.org/show_bug.cgi?id=551260#c17
The binaries used below were all downloaded from sqlite.org.

$ cat fts3-offsets-asplode.sql
CREATE VIRTUAL TABLE ft USING fts3(tokenize=porter, fulltextOne, fulltextTwo);
INSERT INTO ft VALUES(, foo);
INSERT INTO ft VALUES(foo, foo);
SELECT offsets(ft) FROM ft WHERE ft MATCH foo;

$ sqlite3-3.6.22  fts3-offsets-asplode.sql
1 0 0 3
0 0 0 3 1 0 0 3

$ sqlite3-3.6.23  fts3-offsets-asplode.sql
Error: near line 4: database disk image is malformed

My investigation thus far has identified the sqlite3Fts3Offsets implementation 
as the
source of the error.  It seems upset that the first column contains an empty
string and the tokenizer returns SQLITE_DONE.

Andrew

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


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
I tried using STRACE, unfortunately, I am quite new to Linux programming, so
I can't make much sense out of the output. I attached it to this email, in
case some kind soul would like to take a look at it.
The program ran is exactly this:

#include stdio.h
#include stdlib.h
#include sqlite3.h
#include ping.h

int main(void){
sqlite3* db_handle=NULL;

ping_pong(10.0.0.3,2); //IP number + timeout in seconds -- This pings
works fine

if(sqlite3_open(guido.db,db_handle))
{
fprintf(stderr,Error while opening
DB:%s\n,sqlite3_errmsg(db_handle));
exit(1);
}
 if(sqlite3_close(db_handle))
{
fprintf(stderr,Error while closing
DB:%s\n,sqlite3_errmsg(db_handle));
exit(1);
}
ping_pong(10.0.0.3,2); // This ping doesnt work
return 0;
}

On Wed, Mar 24, 2010 at 4:51 AM, Roger Binns rog...@rogerbinns.com wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Martin Sigwald wrote:
  Here is the actual code:
 
  int main(void)
  {
  sqlite3* db_handle;
 
   sqlite3_open(DB_NAME,db_handle);
   sqlite3_close(db_handle);
   my_ping(10.0.0.4);
 
return 0;
  }
 
  If I call close after ping, it works. However, if besides of opening the
 DB
  I perform any query, ping doesnt work either.

 My best guess is that you are making an error with file descriptors.  It
 can be quite easy to accidentally use various values with low numbers
 instead of the actual file descriptor numbers, and you'll get away with
 it until some other code (eg sqlite) opens and closes files.  (Note that
 under some circumstances SQLite can leave file descriptors open even
 after close is called.)

 I suggest using strace and carefully examining the file descriptors used.

 Roger
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.9 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 iEYEARECAAYFAkupxGUACgkQmOOfHg372QTd2ACeNaCEFII4TuVK8ZtTpCvZeFeX
 ivYAnjuLh8uKl1z1jVauy9Fxa60Po9RR
 =AVyR
 -END PGP SIGNATURE-
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

execve(./miercoles.o, [./miercoles.o], [/* 22 vars */]) = 0
brk(0)  = 0x804b000
access(/etc/ld.so.nohwcap, F_OK)  = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb7f17000
access(/etc/ld.so.preload, R_OK)  = -1 ENOENT (No such file or directory)
open(/etc/ld.so.cache, O_RDONLY)  = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=49519, ...}) = 0
mmap2(NULL, 49519, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f0a000
close(3)= 0
access(/etc/ld.so.nohwcap, F_OK)  = -1 ENOENT (No such file or directory)
open(/usr/lib/libsqlite3.so.0, O_RDONLY) = 3
read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\316..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=410036, ...}) = 0
mmap2(NULL, 413188, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb7ea5000
mmap2(0xb7f08000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x62) = 0xb7f08000
close(3)= 0
access(/etc/ld.so.nohwcap, F_OK)  = -1 ENOENT (No such file or directory)
open(/lib/tls/i686/cmov/libc.so.6, O_RDONLY) = 3
read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260e\1..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1364388, ...}) = 0
mmap2(NULL, 1369712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb7d56000
mmap2(0xb7e9f000, 12288, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x149) = 0xb7e9f000
mmap2(0xb7ea2000, 9840, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ea2000
close(3)= 0
access(/etc/ld.so.nohwcap, F_OK)  = -1 ENOENT (No such file or directory)
open(/lib/tls/i686/cmov/libdl.so.2, O_RDONLY) = 3
read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p\n\0\000..., 512) = 
512
fstat64(3, {st_mode=S_IFREG|0644, st_size=9684, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb7d55000
mmap2(NULL, 12412, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb7d51000
mmap2(0xb7d53000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xb7d53000
close(3)= 0
access(/etc/ld.so.nohwcap, F_OK)  = -1 ENOENT (No such file or directory)
open(/lib/tls/i686/cmov/libpthread.so.0, O_RDONLY) = 3
read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20H\0\000..., 512) = 
512
fstat64(3, {st_mode=S_IFREG|0755, st_size=112354, ...}) = 0
mmap2(NULL, 94688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb7d39000
mmap2(0xb7d4d000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13) = 0xb7d4d000
mmap2(0xb7d4f000, 4576, PROT_READ|PROT_WRITE, 

Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
While I could gather, both the open system called generated by the DB and
the socket() syscall are returning a FD=3.
That is, they are both trying to use the same filedescriptor. My guess is
packets get sent to that file descriptor, instead of the port. How can I
changed this? I just followed standar procedure to allocate a socket:
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

Shouldn't the Kernel take care of this and provide an unused FD??

On Wed, Mar 24, 2010 at 11:57 AM, Martin Sigwald msigw...@gmail.com wrote:

 I tried using STRACE, unfortunately, I am quite new to Linux programming,
 so I can't make much sense out of the output. I attached it to this email,
 in case some kind soul would like to take a look at it.
 The program ran is exactly this:

 #include stdio.h
 #include stdlib.h
 #include sqlite3.h
 #include ping.h

 int main(void){
 sqlite3* db_handle=NULL;

 ping_pong(10.0.0.3,2); //IP number + timeout in seconds -- This
 pings works fine

 if(sqlite3_open(guido.db,db_handle))
 {
 fprintf(stderr,Error while opening
 DB:%s\n,sqlite3_errmsg(db_handle));
 exit(1);
 }
  if(sqlite3_close(db_handle))
 {
 fprintf(stderr,Error while closing
 DB:%s\n,sqlite3_errmsg(db_handle));
 exit(1);
 }
 ping_pong(10.0.0.3,2); // This ping doesnt work
 return 0;

 }

 On Wed, Mar 24, 2010 at 4:51 AM, Roger Binns rog...@rogerbinns.comwrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Martin Sigwald wrote:
  Here is the actual code:
 
  int main(void)
  {
  sqlite3* db_handle;
 
   sqlite3_open(DB_NAME,db_handle);
   sqlite3_close(db_handle);
   my_ping(10.0.0.4);
 
return 0;
  }
 
  If I call close after ping, it works. However, if besides of opening the
 DB
  I perform any query, ping doesnt work either.

 My best guess is that you are making an error with file descriptors.  It
 can be quite easy to accidentally use various values with low numbers
 instead of the actual file descriptor numbers, and you'll get away with
 it until some other code (eg sqlite) opens and closes files.  (Note that
 under some circumstances SQLite can leave file descriptors open even
 after close is called.)

 I suggest using strace and carefully examining the file descriptors used.

 Roger
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.9 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 iEYEARECAAYFAkupxGUACgkQmOOfHg372QTd2ACeNaCEFII4TuVK8ZtTpCvZeFeX
 ivYAnjuLh8uKl1z1jVauy9Fxa60Po9RR
 =AVyR
 -END PGP SIGNATURE-
 ___
 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] SQlite C API screwing port access?

2010-03-24 Thread Jay A. Kreibich
On Wed, Mar 24, 2010 at 12:05:58PM -0300, Martin Sigwald scratched on the wall:
 While I could gather, both the open system called generated by the DB and
 the socket() syscall are returning a FD=3.
 That is, they are both trying to use the same filedescriptor. My guess is
 packets get sent to that file descriptor, instead of the port. How can I
 changed this? I just followed standar procedure to allocate a socket:
 sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

  BSD sockets are FDs.

  What port are you talking about?  ICMP doesn't use ports.  Ports
  are not interfaces.
  
  I suggest you get a good book on networking programming and
  debug your networking code.  There is very little chance this is an
  SQLite issue.

  Have you tried putting the ping call before the SQLite calls?
  Between them?

   -j

-- 
Jay A. Kreibich  J A Y  @  K R E I B I.C H 

Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor.   I'll go home and see if I can scrounge up a ruler
 and a piece of string.  --from Anathem by Neal Stephenson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread David Baird
On Wed, Mar 24, 2010 at 9:05 AM, Martin Sigwald msigw...@gmail.com wrote:
 While I could gather, both the open system called generated by the DB and
 the socket() syscall are returning a FD=3.
 That is, they are both trying to use the same filedescriptor. My guess is
 packets get sent to that file descriptor, instead of the port. How can I
 changed this? I just followed standar procedure to allocate a socket:
 sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

 Shouldn't the Kernel take care of this and provide an unused FD??

According to the strace, the kernel is taking care of that properly.
You get a socket, call sendto, select, recvfrom, then close it.  And
then you open guido.db.  Since you just closed your socket, the fd=3
is reused for guido.db.  This is perfectly legitimate.  Something else
funny is going on.  Here's the relevant portions from the strace:

Socket is opened and closed here:

socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
sendto(3, E\0\34\0Eg\0\0\377\1P\223\0\0\0\0\n\0\0\3\10\0;\320#\306...,
28, 0, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr(10.0.0.3)}, 16) = 28
select(4, [3], NULL, NULL, {2, 50}) = 1 (in [3], left {2, 496000})
recvfrom(3, e\0\0\0...@\0\0@\0015\233\n\0\0\3\n\0\0\4\0\0C\320#\306...,
28, 0, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr(10.0.0.3)}, [16]) = 28
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f16000
write(1, El Server 10.0.0.3 esta en el es..., 43) = 43
close(3)= 0

...and then database is opened here:

getcwd(/home/martin, 5000)= 13
open(/home/martin/guido.db, O_RDWR|O_CREAT|O_LARGEFILE, 0644) = 3
fcntl64(3, F_GETFD) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
fstat64(3, {st_mode=S_IFREG|0777, st_size=2048, ...}) = 0
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
I meant socket. I know sockets are FDs. My mistake, sorry.
Yes, I tried putting the call before Sqlite calls and it works perfectly. If
I put it between open and close it works, provided I dont do anything else.
For example, if I open the DB, ping, then run a query then ping again, the
second ping wont work.

On Wed, Mar 24, 2010 at 12:16 PM, Jay A. Kreibich j...@kreibi.ch wrote:

 On Wed, Mar 24, 2010 at 12:05:58PM -0300, Martin Sigwald scratched on the
 wall:
  While I could gather, both the open system called generated by the DB and
  the socket() syscall are returning a FD=3.
  That is, they are both trying to use the same filedescriptor. My guess is
  packets get sent to that file descriptor, instead of the port. How can I
  changed this? I just followed standar procedure to allocate a socket:
  sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

   BSD sockets are FDs.

  What port are you talking about?  ICMP doesn't use ports.  Ports
  are not interfaces.

  I suggest you get a good book on networking programming and
  debug your networking code.  There is very little chance this is an
  SQLite issue.

  Have you tried putting the ping call before the SQLite calls?
  Between them?

   -j

 --
 Jay A. Kreibich  J A Y  @  K R E I B I.C H 

 Our opponent is an alien starship packed with atomic bombs.  We have
  a protractor.   I'll go home and see if I can scrounge up a ruler
  and a piece of string.  --from Anathem by Neal Stephenson
 ___
 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] SQlite C API screwing port access?

2010-03-24 Thread David Baird
On Wed, Mar 24, 2010 at 9:24 AM, David Baird dhba...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 9:05 AM, Martin Sigwald msigw...@gmail.com wrote:
 While I could gather, both the open system called generated by the DB and
 the socket() syscall are returning a FD=3.
 That is, they are both trying to use the same filedescriptor. My guess is
 packets get sent to that file descriptor, instead of the port. How can I
 changed this? I just followed standar procedure to allocate a socket:
 sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

 Shouldn't the Kernel take care of this and provide an unused FD??

 According to the strace, the kernel is taking care of that properly.
 You get a socket, call sendto, select, recvfrom, then close it.  And
 then you open guido.db.  Since you just closed your socket, the fd=3
 is reused for guido.db.  This is perfectly legitimate.  Something else
 funny is going on.  Here's the relevant portions from the strace:

Actually, I just realized that a socket is opened twice in your
strace.  So, here's the portion that includes both socket opens and
the database open:

First socket open and close:

socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
sendto(3, E\0\34\0Eg\0\0\377\1P\223\0\0\0\0\n\0\0\3\10\0;\320#\306...,
28, 0, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr(10.0.0.3)}, 16) = 28
select(4, [3], NULL, NULL, {2, 50}) = 1 (in [3], left {2, 496000})
recvfrom(3, e\0\0\0...@\0\0@\0015\233\n\0\0\3\n\0\0\4\0\0C\320#\306...,
28, 0, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr(10.0.0.3)}, [16]) = 28
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f16000
write(1, El Server 10.0.0.3 esta en el es..., 43) = 43
close(3)= 0

Database open and close (with a dup in the middle that also creates fd=4)...

getcwd(/home/martin, 5000)= 13
open(/home/martin/guido.db, O_RDWR|O_CREAT|O_LARGEFILE, 0644) = 3
fcntl64(3, F_GETFD) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
fstat64(3, {st_mode=S_IFREG|0777, st_size=2048, ...}) = 0
dup(3)  = 4
mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb7537000
mprotect(0xb7537000, 4096, PROT_NONE)   = 0
clone(child_stack=0xb7d374c4,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
parent_tidptr=0xb7d37bd8, {entry_number:6, base_addr:0xb7d37b90,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1},
child_tidptr=0xb7d37bd8) = 6240
mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb6d36000
mprotect(0xb6d36000, 4096, PROT_NONE)   = 0
clone(child_stack=0xb75364c4,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
parent_tidptr=0xb7536bd8, {entry_number:6, base_addr:0xb7536b90,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1},
child_tidptr=0xb7536bd8) = 6241
close(4)= 0
_llseek(3, 0, [0], SEEK_SET)= 0
read(3, SQLite format 3\0\4\0\1\1\0@  \0\0\0\4\0\0\0\0..., 100) = 100
close(3)= 0
getuid32()  = 0

And second socket open and close

socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
sendto(3, E\0\34\0Hs\4\10\377\1I\177\0\0\0\0\n\0\0\3\10\0\276\256...,
28, 0, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr(10.0.0.3)}, 16) = 28
select(4, [3], NULL, NULL, {2, 50}) = 0 (Timeout)
write(1, TIMEOUT\n, 8)= 8
close(3)= 0


In both cases that you call sendto, it appears to have succeeded (i.e.
because they returned a positive value, i.e. 28).  In the second case,
select timed out (as you said it does).

I don't notice any cases of where a stale file descriptor is being
accessed.  I'm stumped :-/

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


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread paivanof
 I don't notice any cases of where a stale file descriptor is being
 accessed.  I'm stumped :-/

Can it be a problem with clone() calls? AFAIK, it's how SQLite checks
if it can work safely from multiple threads. Martin, can you recompile
SQLite with SQLITE_THREADSAFE set to 0 and look if your pinging will
work with that?

BTW, what OS are you using, what compiler and what is your compilation command?

Also it would be interesting to see strace results when your
successful pinging is made before sqlite3_close() and when
unsuccessful pinging is made after statement execution.


Pavel

On Wed, Mar 24, 2010 at 11:45 AM, David Baird dhba...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 9:24 AM, David Baird dhba...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 9:05 AM, Martin Sigwald msigw...@gmail.com wrote:
 While I could gather, both the open system called generated by the DB and
 the socket() syscall are returning a FD=3.
 That is, they are both trying to use the same filedescriptor. My guess is
 packets get sent to that file descriptor, instead of the port. How can I
 changed this? I just followed standar procedure to allocate a socket:
 sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))

 Shouldn't the Kernel take care of this and provide an unused FD??

 According to the strace, the kernel is taking care of that properly.
 You get a socket, call sendto, select, recvfrom, then close it.  And
 then you open guido.db.  Since you just closed your socket, the fd=3
 is reused for guido.db.  This is perfectly legitimate.  Something else
 funny is going on.  Here's the relevant portions from the strace:

 Actually, I just realized that a socket is opened twice in your
 strace.  So, here's the portion that includes both socket opens and
 the database open:

 First socket open and close:

 socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
 setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
 sendto(3, E\0\34\0Eg\0\0\377\1P\223\0\0\0\0\n\0\0\3\10\0;\320#\306...,
 28, 0, {sa_family=AF_INET, sin_port=htons(0),
 sin_addr=inet_addr(10.0.0.3)}, 16) = 28
 select(4, [3], NULL, NULL, {2, 50}) = 1 (in [3], left {2, 496000})
 recvfrom(3, e\0\0\0...@\0\0@\0015\233\n\0\0\3\n\0\0\4\0\0C\320#\306...,
 28, 0, {sa_family=AF_INET, sin_port=htons(0),
 sin_addr=inet_addr(10.0.0.3)}, [16]) = 28
 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
 0) = 0xb7f16000
 write(1, El Server 10.0.0.3 esta en el es..., 43) = 43
 close(3)                                = 0

 Database open and close (with a dup in the middle that also creates fd=4)...

 getcwd(/home/martin, 5000)            = 13
 open(/home/martin/guido.db, O_RDWR|O_CREAT|O_LARGEFILE, 0644) = 3
 fcntl64(3, F_GETFD)                     = 0
 fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
 fstat64(3, {st_mode=S_IFREG|0777, st_size=2048, ...}) = 0
 dup(3)                                  = 4
 mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
 -1, 0) = 0xb7537000
 mprotect(0xb7537000, 4096, PROT_NONE)   = 0
 clone(child_stack=0xb7d374c4,
 flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
 parent_tidptr=0xb7d37bd8, {entry_number:6, base_addr:0xb7d37b90,
 limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
 limit_in_pages:1, seg_not_present:0, useable:1},
 child_tidptr=0xb7d37bd8) = 6240
 mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
 -1, 0) = 0xb6d36000
 mprotect(0xb6d36000, 4096, PROT_NONE)   = 0
 clone(child_stack=0xb75364c4,
 flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
 parent_tidptr=0xb7536bd8, {entry_number:6, base_addr:0xb7536b90,
 limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
 limit_in_pages:1, seg_not_present:0, useable:1},
 child_tidptr=0xb7536bd8) = 6241
 close(4)                                = 0
 _llseek(3, 0, [0], SEEK_SET)            = 0
 read(3, SQLite format 3\0\4\0\1\1\0@  \0\0\0\4\0\0\0\0..., 100) = 100
 close(3)                                = 0
 getuid32()                              = 0

 And second socket open and close

 socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
 setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
 sendto(3, E\0\34\0Hs\4\10\377\1I\177\0\0\0\0\n\0\0\3\10\0\276\256...,
 28, 0, {sa_family=AF_INET, sin_port=htons(0),
 sin_addr=inet_addr(10.0.0.3)}, 16) = 28
 select(4, [3], NULL, NULL, {2, 50}) = 0 (Timeout)
 write(1, TIMEOUT\n, 8)                = 8
 close(3)                                = 0


 In both cases that you call sendto, it appears to have succeeded (i.e.
 because they returned a positive value, i.e. 28).  In the second case,
 select timed out (as you said it does).

 I don't notice any cases of where a stale file descriptor is being
 accessed.  I'm stumped :-/

 -David
 ___
 sqlite-users 

Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
I'm attaching the strace output for the following code you asked:

int main(void){
sqlite3* db_handle=NULL;
if(sqlite3_open(guido.db,db_handle))
{ //abro DB
fprintf(stderr,Error while open
DB:%s\n,sqlite3_errmsg(db_handle));
printf(No pude abrir la DB\n);
exit(1);
}
 ping_pong(10.0.0.3,2);
 if(sqlite3_close(db_handle))
{
fprintf(stderr,Error while open
DB:%s\n,sqlite3_errmsg(db_handle));
printf(No pude abrir la DB\n);
exit(1);
  }

return 0;
}

I' running Ubuntu 8.04, using gcc like this:
gcc ping.c main.c -o output.o -lsqlite3

How do I compile that with the threadsafe otpion you mentioned?

Thanks a lot for your help.
Martin


On Wed, Mar 24, 2010 at 1:09 PM, paivanof paiva...@gmail.com wrote:

  I don't notice any cases of where a stale file descriptor is being
  accessed.  I'm stumped :-/

 Can it be a problem with clone() calls? AFAIK, it's how SQLite checks
 if it can work safely from multiple threads. Martin, can you recompile
 SQLite with SQLITE_THREADSAFE set to 0 and look if your pinging will
 work with that?

 BTW, what OS are you using, what compiler and what is your compilation
 command?

 Also it would be interesting to see strace results when your
 successful pinging is made before sqlite3_close() and when
 unsuccessful pinging is made after statement execution.


 Pavel

 On Wed, Mar 24, 2010 at 11:45 AM, David Baird dhba...@gmail.com wrote:
  On Wed, Mar 24, 2010 at 9:24 AM, David Baird dhba...@gmail.com wrote:
  On Wed, Mar 24, 2010 at 9:05 AM, Martin Sigwald msigw...@gmail.com
 wrote:
  While I could gather, both the open system called generated by the DB
 and
  the socket() syscall are returning a FD=3.
  That is, they are both trying to use the same filedescriptor. My guess
 is
  packets get sent to that file descriptor, instead of the port. How can
 I
  changed this? I just followed standar procedure to allocate a socket:
  sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP))
 
  Shouldn't the Kernel take care of this and provide an unused FD??
 
  According to the strace, the kernel is taking care of that properly.
  You get a socket, call sendto, select, recvfrom, then close it.  And
  then you open guido.db.  Since you just closed your socket, the fd=3
  is reused for guido.db.  This is perfectly legitimate.  Something else
  funny is going on.  Here's the relevant portions from the strace:
 
  Actually, I just realized that a socket is opened twice in your
  strace.  So, here's the portion that includes both socket opens and
  the database open:
 
  First socket open and close:
 
  socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
  setsockopt(3, SOL_IP, IP_HDRINCL, [1], 4) = 0
  sendto(3, E\0\34\0Eg\0\0\377\1P\223\0\0\0\0\n\0\0\3\10\0;\320#\306...,
  28, 0, {sa_family=AF_INET, sin_port=htons(0),
  sin_addr=inet_addr(10.0.0.3)}, 16) = 28
  select(4, [3], NULL, NULL, {2, 50}) = 1 (in [3], left {2, 496000})
  recvfrom(3, e\0\0\0...@\0\0@
 \0015\233\n\0\0\3\n\0\0\4\0\0C\320#\306...,
  28, 0, {sa_family=AF_INET, sin_port=htons(0),
  sin_addr=inet_addr(10.0.0.3)}, [16]) = 28
  fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
  0) = 0xb7f16000
  write(1, El Server 10.0.0.3 esta en el es..., 43) = 43
  close(3)= 0
 
  Database open and close (with a dup in the middle that also creates
 fd=4)...
 
  getcwd(/home/martin, 5000)= 13
  open(/home/martin/guido.db, O_RDWR|O_CREAT|O_LARGEFILE, 0644) = 3
  fcntl64(3, F_GETFD) = 0
  fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
  fstat64(3, {st_mode=S_IFREG|0777, st_size=2048, ...}) = 0
  dup(3)  = 4
  mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
  -1, 0) = 0xb7537000
  mprotect(0xb7537000, 4096, PROT_NONE)   = 0
  clone(child_stack=0xb7d374c4,
 
 flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
  parent_tidptr=0xb7d37bd8, {entry_number:6, base_addr:0xb7d37b90,
  limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
  limit_in_pages:1, seg_not_present:0, useable:1},
  child_tidptr=0xb7d37bd8) = 6240
  mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
  -1, 0) = 0xb6d36000
  mprotect(0xb6d36000, 4096, PROT_NONE)   = 0
  clone(child_stack=0xb75364c4,
 
 flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
  parent_tidptr=0xb7536bd8, {entry_number:6, base_addr:0xb7536b90,
  limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
  limit_in_pages:1, seg_not_present:0, useable:1},
  child_tidptr=0xb7536bd8) = 6241
  close(4)= 0
  _llseek(3, 0, [0], SEEK_SET)= 0
  read(3, SQLite format 

Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread David Baird
On Wed, Mar 24, 2010 at 9:42 AM, Martin Sigwald msigw...@gmail.com wrote:
 I meant socket. I know sockets are FDs. My mistake, sorry.
 Yes, I tried putting the call before Sqlite calls and it works perfectly. If
 I put it between open and close it works, provided I dont do anything else.
 For example, if I open the DB, ping, then run a query then ping again, the
 second ping wont work.

What if you try doing two pings in a row?  Does the second ping ever
work?  Does it always work?  Does it work sometimes?
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
Doing N pings after a _close or a query has the same result as doind one:
not one of them works.

On Wed, Mar 24, 2010 at 2:07 PM, David Baird dhba...@gmail.com wrote:

 On Wed, Mar 24, 2010 at 9:42 AM, Martin Sigwald msigw...@gmail.com
 wrote:
  I meant socket. I know sockets are FDs. My mistake, sorry.
  Yes, I tried putting the call before Sqlite calls and it works perfectly.
 If
  I put it between open and close it works, provided I dont do anything
 else.
  For example, if I open the DB, ping, then run a query then ping again,
 the
  second ping wont work.

 What if you try doing two pings in a row?  Does the second ping ever
 work?  Does it always work?  Does it work sometimes?
 ___
 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] SQlite C API screwing port access?

2010-03-24 Thread David Baird
On Wed, Mar 24, 2010 at 11:09 AM, Martin Sigwald msigw...@gmail.com wrote:
 Doing N pings after a _close or a query has the same result as doind one:
 not one of them works.

Do 2 pings work ever?  For example, how about each of these scenarios?

open_db
ping
ping
close_db

or

ping
ping

or

open_db
close_db
ping
ping

?

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


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
Problem Solved: As some one point out, it was MY fault.
When allocating memory for my ICMP packets I wasnt doind a bzero to fill all
fields with 0, so some garbage generated by Sqlite use of memory was
corrupting my packets.
Thank you all for the help. One of the best user groups I ever met. Terrible
sorry for wasting your time.

On Wed, Mar 24, 2010 at 2:12 PM, David Baird dhba...@gmail.com wrote:

 On Wed, Mar 24, 2010 at 11:09 AM, Martin Sigwald msigw...@gmail.com
 wrote:
  Doing N pings after a _close or a query has the same result as doind one:
  not one of them works.

 Do 2 pings work ever?  For example, how about each of these scenarios?

 open_db
 ping
 ping
 close_db

 or

 ping
 ping

 or

 open_db
 close_db
 ping
 ping

 ?

 -David
 ___
 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] SQlite C API screwing port access?

2010-03-24 Thread Pavel Ivanov
 When allocating memory for my ICMP packets I wasnt doind a bzero to fill all
 fields with 0, so some garbage generated by Sqlite use of memory was
 corrupting my packets.

And still try please my very first suggestion - run you program with
valgrind (just to get used to it and to use it right away next time).
You'll see that it shows you all reading of uninitialized memory...


Pavel

On Wed, Mar 24, 2010 at 1:19 PM, Martin Sigwald msigw...@gmail.com wrote:
 Problem Solved: As some one point out, it was MY fault.
 When allocating memory for my ICMP packets I wasnt doind a bzero to fill all
 fields with 0, so some garbage generated by Sqlite use of memory was
 corrupting my packets.
 Thank you all for the help. One of the best user groups I ever met. Terrible
 sorry for wasting your time.

 On Wed, Mar 24, 2010 at 2:12 PM, David Baird dhba...@gmail.com wrote:

 On Wed, Mar 24, 2010 at 11:09 AM, Martin Sigwald msigw...@gmail.com
 wrote:
  Doing N pings after a _close or a query has the same result as doind one:
  not one of them works.

 Do 2 pings work ever?  For example, how about each of these scenarios?

 open_db
 ping
 ping
 close_db

 or

 ping
 ping

 or

 open_db
 close_db
 ping
 ping

 ?

 -David
 ___
 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] SQlite C API screwing port access?

2010-03-24 Thread David Baird
On Wed, Mar 24, 2010 at 11:19 AM, Martin Sigwald msigw...@gmail.com wrote:
 Problem Solved: As some one point out, it was MY fault.
 When allocating memory for my ICMP packets I wasnt doind a bzero to fill all
 fields with 0, so some garbage generated by Sqlite use of memory was
 corrupting my packets.
 Thank you all for the help. One of the best user groups I ever met. Terrible
 sorry for wasting your time.

Glad you found it ... forgetting to initialize data happens even to
the best of us sometimes.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQlite C API screwing port access?

2010-03-24 Thread Martin Sigwald
Will do. Thanks again to everyone. At least I learned how to use strace,
which I didnt no.

On Wed, Mar 24, 2010 at 2:25 PM, Pavel Ivanov paiva...@gmail.com wrote:

  When allocating memory for my ICMP packets I wasnt doind a bzero to fill
 all
  fields with 0, so some garbage generated by Sqlite use of memory was
  corrupting my packets.

 And still try please my very first suggestion - run you program with
 valgrind (just to get used to it and to use it right away next time).
 You'll see that it shows you all reading of uninitialized memory...


 Pavel

 On Wed, Mar 24, 2010 at 1:19 PM, Martin Sigwald msigw...@gmail.com
 wrote:
  Problem Solved: As some one point out, it was MY fault.
  When allocating memory for my ICMP packets I wasnt doind a bzero to fill
 all
  fields with 0, so some garbage generated by Sqlite use of memory was
  corrupting my packets.
  Thank you all for the help. One of the best user groups I ever met.
 Terrible
  sorry for wasting your time.
 
  On Wed, Mar 24, 2010 at 2:12 PM, David Baird dhba...@gmail.com wrote:
 
  On Wed, Mar 24, 2010 at 11:09 AM, Martin Sigwald msigw...@gmail.com
  wrote:
   Doing N pings after a _close or a query has the same result as doind
 one:
   not one of them works.
 
  Do 2 pings work ever?  For example, how about each of these scenarios?
 
  open_db
  ping
  ping
  close_db
 
  or
 
  ping
  ping
 
  or
 
  open_db
  close_db
  ping
  ping
 
  ?
 
  -David
  ___
  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

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


Re: [sqlite] Question about binding

2010-03-24 Thread Pavel Ivanov
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

Probably this will help you: http://www.sqlite.org/c3ref/bind_blob.html.


Pavel

On Tue, Mar 23, 2010 at 3:48 PM, Vance E. Neff ven...@intouchmi.com wrote:
 Thanks to all those who responded!  It was quite educational.
 I'm using the zentus java jdbc wrapper.  It seems to only support an
 index # for the binding index so I'm stuck with being careful as to how
 I count ?s.
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

 Vance

 D. Richard Hipp wrote:
 On Mar 19, 2010, at 3:29 PM, David Bicking wrote:


 --- On Fri, 3/19/10, Vance E. Neff ven...@intouchmi.com wrote:

 snip
 UPDATE table1 set (?, ?, ?) WHERE col1=? and col2=?;

 I've never used binding before but have known it is a good
 idea in order
 to avoid injection of bad stuff.

 Vance

 You count the question marks from left to right.

 UPDATE table1 set (1, 2, 3) WHERE col1=4 and col2=5;
 You can also put the index number you want to use after the ? so
 they can be in any order you want.

 Better still is to use a symbolic name for the parameters.  The
 symbolic names can be any identifier that begins with $, :, or @.
 Examples:

     UPDATE table1 SET col1=$c1val, co...@c2val, col3=:c3val
       WHERE co...@c2val AND col3=:c3val;

 You still have to translate the symbolic name into a parameter index
 before you bind it.  The sqlite3_bind_parameter_index() routine will
 do that for you.

 In the programs I write, I always try to use symbolic names for
 parameters and I rig the infrastructure to handle the mapping from
 symbolic name to parameter index.  For example, if you are using the
 TCL interface to SQLite, you just specify TCL variables embedded in
 the SQL:

       db eval {UPDATE table1 SET col1=$c1val WHERE col2=$c2val}

 In the statement above, the TCL interface automatically looks up the
 values of TCL variables $c1val and $c2val and binds them appropriately
 before running the statement.  It doesn't get any cleaner than this.
 Unfortunately, other programming languages require more complex
 syntax.  In the implementation of Fossil I do this:

       db_prepare(stmt, UPDATE table1 SET col1=$c1val WHERE col2=
 $c2val);
       db_bind_int(stmt, $c1val, 123);
       db_bind_double(stmt, $c2val, 456.78);
       db_step(stmt);
       db_finalize(stmt);

 The db_bind_int() and db_bind_double() and similar routines wrap the
 sqlite3_bind_x() and sqlite3_bind_parameter_index() calls.

 If we've learned one thing over the history of computing it is that
 programmers are notoriously bad at counting parameters and that
 symbolic names tend to be much better at avoiding bugs.

 D. Richard Hipp
 d...@hwaci.com



 ___
 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] Question about binding

2010-03-24 Thread a1rex
* :VVV 
* @VVV 
* $VVV 
Are above bindings the same? (Just different prefix to VVV)?  
Thank you,
Samuel

From: Pavel Ivanov paiva...@gmail.com
To: General Discussion of SQLite Database sqlite-users@sqlite.org
Sent: Wed, March 24, 2010 2:16:34 PM
Subject: Re: [sqlite] Question about binding

 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

Probably this will help you: http://www.sqlite.org/c3ref/bind_blob.html.


Pavel

On Tue, Mar 23, 2010 at 3:48 PM, Vance E. Neff ven...@intouchmi.com wrote:
 Thanks to all those who responded!  It was quite educational.
 I'm using the zentus java jdbc wrapper.  It seems to only support an
 index # for the binding index so I'm stuck with being careful as to how
 I count ?s.
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

 Vance

 D. Richard Hipp wrote:
 On Mar 19, 2010, at 3:29 PM, David Bicking wrote:


 --- On Fri, 3/19/10, Vance E. Neff ven...@intouchmi.com wrote:

 snip
 UPDATE table1 set (?, ?, ?) WHERE col1=? and col2=?;

 I've never used binding before but have known it is a good
 idea in order
 to avoid injection of bad stuff.

 Vance

 You count the question marks from left to right.

 UPDATE table1 set (1, 2, 3) WHERE col1=4 and col2=5;
 You can also put the index number you want to use after the ? so
 they can be in any order you want.

 Better still is to use a symbolic name for the parameters.  The
 symbolic names can be any identifier that begins with $, :, or @.
 Examples:

 UPDATE table1 SET col1=$c1val, co...@c2val, col3=:c3val
   WHERE co...@c2val AND col3=:c3val;

 You still have to translate the symbolic name into a parameter index
 before you bind it.  The sqlite3_bind_parameter_index() routine will
 do that for you.

 In the programs I write, I always try to use symbolic names for
 parameters and I rig the infrastructure to handle the mapping from
 symbolic name to parameter index.  For example, if you are using the
 TCL interface to SQLite, you just specify TCL variables embedded in
 the SQL:

   db eval {UPDATE table1 SET col1=$c1val WHERE col2=$c2val}

 In the statement above, the TCL interface automatically looks up the
 values of TCL variables $c1val and $c2val and binds them appropriately
 before running the statement.  It doesn't get any cleaner than this.
 Unfortunately, other programming languages require more complex
 syntax.  In the implementation of Fossil I do this:

   db_prepare(stmt, UPDATE table1 SET col1=$c1val WHERE col2=
 $c2val);
   db_bind_int(stmt, $c1val, 123);
   db_bind_double(stmt, $c2val, 456.78);
   db_step(stmt);
   db_finalize(stmt);

 The db_bind_int() and db_bind_double() and similar routines wrap the
 sqlite3_bind_x() and sqlite3_bind_parameter_index() calls.

 If we've learned one thing over the history of computing it is that
 programmers are notoriously bad at counting parameters and that
 symbolic names tend to be much better at avoiding bugs.

 D. Richard Hipp
 d...@hwaci.com



 ___
 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



  __
Connect with friends from any web browser - no download required. Try the new 
Yahoo! Canada Messenger for the Web BETA at 
http://ca.messenger.yahoo.com/webmessengerpromo.php
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Question about binding

2010-03-24 Thread Pavel Ivanov
Yes, they are the same.

Pavel

On Wed, Mar 24, 2010 at 4:04 PM, a1rex a1rex2...@yahoo.com wrote:
    * :VVV
    * @VVV
    * $VVV
 Are above bindings the same? (Just different prefix to VVV)?
 Thank you,
 Samuel
 
 From: Pavel Ivanov paiva...@gmail.com
 To: General Discussion of SQLite Database sqlite-users@sqlite.org
 Sent: Wed, March 24, 2010 2:16:34 PM
 Subject: Re: [sqlite] Question about binding

 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

 Probably this will help you: http://www.sqlite.org/c3ref/bind_blob.html.


 Pavel

 On Tue, Mar 23, 2010 at 3:48 PM, Vance E. Neff ven...@intouchmi.com wrote:
 Thanks to all those who responded!  It was quite educational.
 I'm using the zentus java jdbc wrapper.  It seems to only support an
 index # for the binding index so I'm stuck with being careful as to how
 I count ?s.
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

 Vance

 D. Richard Hipp wrote:
 On Mar 19, 2010, at 3:29 PM, David Bicking wrote:


 --- On Fri, 3/19/10, Vance E. Neff ven...@intouchmi.com wrote:

 snip
 UPDATE table1 set (?, ?, ?) WHERE col1=? and col2=?;

 I've never used binding before but have known it is a good
 idea in order
 to avoid injection of bad stuff.

 Vance

 You count the question marks from left to right.

 UPDATE table1 set (1, 2, 3) WHERE col1=4 and col2=5;
 You can also put the index number you want to use after the ? so
 they can be in any order you want.

 Better still is to use a symbolic name for the parameters.  The
 symbolic names can be any identifier that begins with $, :, or @.
 Examples:

     UPDATE table1 SET col1=$c1val, co...@c2val, col3=:c3val
       WHERE co...@c2val AND col3=:c3val;

 You still have to translate the symbolic name into a parameter index
 before you bind it.  The sqlite3_bind_parameter_index() routine will
 do that for you.

 In the programs I write, I always try to use symbolic names for
 parameters and I rig the infrastructure to handle the mapping from
 symbolic name to parameter index.  For example, if you are using the
 TCL interface to SQLite, you just specify TCL variables embedded in
 the SQL:

       db eval {UPDATE table1 SET col1=$c1val WHERE col2=$c2val}

 In the statement above, the TCL interface automatically looks up the
 values of TCL variables $c1val and $c2val and binds them appropriately
 before running the statement.  It doesn't get any cleaner than this.
 Unfortunately, other programming languages require more complex
 syntax.  In the implementation of Fossil I do this:

       db_prepare(stmt, UPDATE table1 SET col1=$c1val WHERE col2=
 $c2val);
       db_bind_int(stmt, $c1val, 123);
       db_bind_double(stmt, $c2val, 456.78);
       db_step(stmt);
       db_finalize(stmt);

 The db_bind_int() and db_bind_double() and similar routines wrap the
 sqlite3_bind_x() and sqlite3_bind_parameter_index() calls.

 If we've learned one thing over the history of computing it is that
 programmers are notoriously bad at counting parameters and that
 symbolic names tend to be much better at avoiding bugs.

 D. Richard Hipp
 d...@hwaci.com



 ___
 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



      __
 Connect with friends from any web browser - no download required. Try the new 
 Yahoo! Canada Messenger for the Web BETA at 
 http://ca.messenger.yahoo.com/webmessengerpromo.php
 ___
 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] corruption problem with attached macintosh database

2010-03-24 Thread Dave Dyer

I think there is a locking problem that leads to corrupt databases
under quite reproducable conditions.  The conditions are:

database resident on a mac file sustem
mounted as a drive letter on a pc
the main database is open and shared by sqlite running on both computers.
the auxiliary database is attached and updated simultaneously from both 
computers

Under these circumstances, both applications typically get 
error 11, disk image is corrupted errors while attempting 
to update the auxiliary database.

Note that the main database, which is updated periodically, doesn't have
a corruption problem, and that this is only a problem with databases resident
on a mac.  The same scenario, with databases resident on the PC disk, works
fine.

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


Re: [sqlite] R*Tree and sqlite3_last_insert_rowid() API - possible bug?

2010-03-24 Thread Wanadoo Hartwig
Hi Dan,

Am 22.03.2010 um 05:08 schrieb Dan Kennedy:

 
 On Mar 22, 2010, at 4:16 AM, Wanadoo Hartwig wrote:
 
 Hi Minar, hi Dan,
 
 there is a similar bug in the FTS3 module. But here the  
 sqlite_last_rowid may return a wrong value.
 
 How do we reproduce this bug?
 
 Dan.
 
 
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

there is already an open ticket from 2009-12-01 under Open FTS3 tickets 
describing how to reproduce it. My e-mail was more meant to draw attention to 
the extensions (especially virtual table stuff). But if you are able to fix the 
bug I would really really appreciate it because then I do not have to program 
around the feature anymore.

Hartwig

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


Re: [sqlite] Question about binding

2010-03-24 Thread Adam DeVita
Good day,

For the sake of fun, I have to share this - especially with tall this talk
of binding all the parameters.

void poem(CString pth)
{

sqlite3_stmt *ppStmt; //statement pointer
sqlite3 *db; //database
const char *pzTail;
char *pzerr;

if( sqlite3_open(pth, db) ){
printf(Can't open database! );
sqlite3_close(db);
return ;
}

CString csql;
csql.Format(Create table if not exists poem (verseno integer primary
key, rings int, location text));   //sets the string.
int status = sqlite3_prepare_v2(db,csql, /* SQL statement, UTF-16
encoded */   csql.GetLength(),  /* Maximum length of zSql in bytes. */
ppStmt,  /* OUT: Statement handle */
pzTail  /*  OUT: Pointer to unused portion of zSql  which
I'm not going to use because I want to bind things different ways.*/ );

if (status != SQLITE_OK){
printf(something is wrong, shame, shame, shame. );
sqlite3_close(db);
return ;
}
sqlite3_step(ppStmt);
sqlite3_finalize(ppStmt);


int rings[5] ={3 , 7 ,9,1 ,1};
CString verse1 =_T( for elvin kings, under the sky);
CString verse2 =_T( for dwarf lords, in their halls of stone);
CString verse3 =_T( for mortal men, doomed to die);
CString verse4 =_T( for the dark lord, on his dark throne );

csql.Format( insert into poem (rings, location) values (?, ?) );
status = sqlite3_prepare_v2(db,csql, /* SQL statement, UTF-16 encoded
*/   csql.GetLength(),  /* Maximum length of zSql in bytes.
*/ppStmt,  /* OUT: Statement handle */
pzTail  /*  OUT: Pointer to unused portion of zSql */ );

if (status != SQLITE_OK){
printf(something is wrong, like %d,status);
sqlite3_close(db);
return ;
}
int ring_verse =0;
sqlite3_bind_int (ppStmt, 1, rings[ring_verse]);
sqlite3_bind_text(ppStmt, 2, verse1, verse1.GetLength(), SQLITE_STATIC);
sqlite3_step(ppStmt);
ring_verse++;



csql.Format( insert into poem (rings, location) values (?002, ?001)
);
status = sqlite3_prepare_v2(db,csql, /* SQL statement, UTF-16 encoded
*/csql.GetLength(),  /* Maximum length of zSql in bytes. */
ppStmt,  /* OUT: Statement handle */
pzTail  /*  OUT: Pointer to unused portion of zSql */ );

if (status != SQLITE_OK){
printf(something is wrong %d,status);
sqlite3_close(db);
return ;
}
sqlite3_bind_text(ppStmt, 1, verse2, verse2.GetLength(), SQLITE_STATIC);
sqlite3_bind_int (ppStmt, 2, rings[ring_verse]);
sqlite3_step(ppStmt);
ring_verse++;

csql.Format( insert into poem (rings, location) values ($ringy, :versy)
);
status = sqlite3_prepare_v2(db,csql, /* SQL statement, UTF-16 encoded */
csql.GetLength(),  /* Maximum length of zSql in bytes. */
ppStmt,  /* OUT: Statement handle */
pzTail  /*  OUT: Pointer to unused portion of zSql */ );

if (status != SQLITE_OK){
printf(something is wrong %d,status);
sqlite3_close(db);
return ;
}
sqlite3_bind_text(ppStmt, sqlite3_bind_parameter_index(ppStmt,
:versy), verse3, verse3.GetLength(), SQLITE_STATIC);
sqlite3_bind_int (ppStmt, sqlite3_bind_parameter_index(ppStmt,
$ringy), rings[ring_verse]);
sqlite3_step(ppStmt);
ring_verse++;



CString csrepeated =_T(\nin the land of Mordor, where the shadows
lie.);
csql.Format( insert into poem (rings, location) values (@ringy,  :versy
|| :repeats) );
status = sqlite3_prepare_v2(db,csql, /* SQL statement, UTF-16 encoded */
csql.GetLength(),  /* Maximum length of zSql in bytes. */
ppStmt,  /* OUT: Statement handle */
pzTail  /*  OUT: Pointer to unused portion of zSql */ );

if (status != SQLITE_OK){
printf(something is wrong %d,status);
sqlite3_close(db);
return ;
}
sqlite3_bind_text(ppStmt, sqlite3_bind_parameter_index(ppStmt,
:repeats), csrepeated, csrepeated.GetLength(), SQLITE_STATIC);
sqlite3_bind_text(ppStmt, sqlite3_bind_parameter_index(ppStmt,
:versy), verse4, verse4.GetLength(), SQLITE_STATIC);
sqlite3_bind_int (ppStmt, sqlite3_bind_parameter_index(ppStmt,
@ringy), rings[ring_verse]);
sqlite3_step(ppStmt);
ring_verse++;

//and finally


verse3.Format( to bring them all and in the darkness BIND them );
csql.Format( insert into poem (rings, location) values (@ringy, ' ring
to rule them all '|| @ringy ||' ring to find them, '|| @ringy ||:versy ||
:repeats) );
status = sqlite3_prepare_v2(db,csql,csql.GetLength(), ppStmt,
pzTail   );

if (status != SQLITE_OK){
printf(something is wrong %d,status);
sqlite3_close(db);
return ;
}
sqlite3_bind_text(ppStmt, sqlite3_bind_parameter_index(ppStmt,
:repeats), csrepeated, csrepeated.GetLength(), SQLITE_STATIC);
sqlite3_bind_text(ppStmt, 

Re: [sqlite] Question about binding

2010-03-24 Thread Vance E. Neff
Thanks Pavel!

Vance

Pavel Ivanov wrote:
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?
 
 Probably this will help you: http://www.sqlite.org/c3ref/bind_blob.html.
 
 
 Pavel
 
 On Tue, Mar 23, 2010 at 3:48 PM, Vance E. Neff ven...@intouchmi.com wrote:
 Thanks to all those who responded!  It was quite educational.
 I'm using the zentus java jdbc wrapper.  It seems to only support an
 index # for the binding index so I'm stuck with being careful as to how
 I count ?s.
 Is there documentation that talks about about the various binding place
 holders or is this a standard SQL construct?

 Vance

 D. Richard Hipp wrote:
 On Mar 19, 2010, at 3:29 PM, David Bicking wrote:

 --- On Fri, 3/19/10, Vance E. Neff ven...@intouchmi.com wrote:

 snip
 UPDATE table1 set (?, ?, ?) WHERE col1=? and col2=?;

 I've never used binding before but have known it is a good
 idea in order
 to avoid injection of bad stuff.

 Vance

 You count the question marks from left to right.

 UPDATE table1 set (1, 2, 3) WHERE col1=4 and col2=5;
 You can also put the index number you want to use after the ? so
 they can be in any order you want.
 Better still is to use a symbolic name for the parameters.  The
 symbolic names can be any identifier that begins with $, :, or @.
 Examples:

 UPDATE table1 SET col1=$c1val, co...@c2val, col3=:c3val
   WHERE co...@c2val AND col3=:c3val;

 You still have to translate the symbolic name into a parameter index
 before you bind it.  The sqlite3_bind_parameter_index() routine will
 do that for you.

 In the programs I write, I always try to use symbolic names for
 parameters and I rig the infrastructure to handle the mapping from
 symbolic name to parameter index.  For example, if you are using the
 TCL interface to SQLite, you just specify TCL variables embedded in
 the SQL:

   db eval {UPDATE table1 SET col1=$c1val WHERE col2=$c2val}

 In the statement above, the TCL interface automatically looks up the
 values of TCL variables $c1val and $c2val and binds them appropriately
 before running the statement.  It doesn't get any cleaner than this.
 Unfortunately, other programming languages require more complex
 syntax.  In the implementation of Fossil I do this:

   db_prepare(stmt, UPDATE table1 SET col1=$c1val WHERE col2=
 $c2val);
   db_bind_int(stmt, $c1val, 123);
   db_bind_double(stmt, $c2val, 456.78);
   db_step(stmt);
   db_finalize(stmt);

 The db_bind_int() and db_bind_double() and similar routines wrap the
 sqlite3_bind_x() and sqlite3_bind_parameter_index() calls.

 If we've learned one thing over the history of computing it is that
 programmers are notoriously bad at counting parameters and that
 symbolic names tend to be much better at avoiding bugs.

 D. Richard Hipp
 d...@hwaci.com



 ___
 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
 
 

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


[sqlite] more on mac database corruption

2010-03-24 Thread Dave Dyer
I was able to reproduce the problem using a trivial set of commands
to the standard sqlite command tool:


On the Mac:

gorp:~/2010 yeartech/yearbook tools/resource davedyer$ 
/applications/utilities/sqlite3-shell actiontool2.sqlite
SQLite version 3.6.10 with the Encryption Extension
sqlite attach database 'indexer.sqlite' as indexer;
sqlite begin transaction;


On the PC:

M:\2010 yeartech\yearbook tools\resourcesqlite3 actiontool2.sqlite
sqlite attach database 'indexer.sqlite' as indexer;
sqlite begin transaction;
sqlite delete from indexer.preference_table;
sqlite insert into indexer.preference_table select * from preference_table;
sqlite commit;

On the Mac:


sqlite delete from indexer.preferences_table;
SQL error: no such table: indexer.preferences_table
sqlite delete from indexer.preference_table;
sqlite insert into indexer.preference_table select * from preference_table;
SQL error: database disk image is malformed
sqlite 

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


Re: [sqlite] corruption problem with attached macintosh database

2010-03-24 Thread Simon Slavin

On 24 Mar 2010, at 8:50pm, Dave Dyer wrote:

 database resident on a mac file sustem
 mounted as a drive letter on a pc
 the main database is open and shared by sqlite running on both computers.
 the auxiliary database is attached and updated simultaneously from both 
 computers

Could you help us by adding any of the following details ?

What OS is the Mac running ?
What OS is the PC running ?
What protocol is being used to access the Mac file share ?
Is the file-sharing host accessing the database as a shared file, or as a file 
on its hard disk ?

 Under these circumstances, both applications typically get 
 error 11, disk image is corrupted errors while attempting 
 to update the auxiliary database.

Does this happen without any data-changing instructions ?  In other words can I 
get this fault using only _open, ATTACH and lots of SELECT commands until 
something falls over ?  Or even just repeated _open, ATTACH and _close until 
something falls over ?

 Note that the main database, which is updated periodically, doesn't have
 a corruption problem,

Are both 'main' and 'auxiliary' on in the same folder, being accessed the same 
way ?

 and that this is only a problem with databases resident
 on a mac.  The same scenario, with databases resident on the PC disk, works
 fine.

When the databases are on the PC disk, what protocol is the Mac using to access 
them ?

Thanks for your help.

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


Re: [sqlite] corruption problem with attached macintosh database

2010-03-24 Thread Dave Dyer


Could you help us by adding any of the following details ?

What OS is the Mac running ?

OSX 10.4.11 for me, but also snow leopard.

What OS is the PC running ?

Windows 2003 server for me, but also XP (note the file systems are all mac
file systems)

What protocol is being used to access the Mac file share ?

Presumably windows standard file sharing protocol over tcp

Is the file-sharing host accessing the database as a shared file, or as a file 
on its hard disk ?

The mac acting as file host is accessing the file as a local file.


Does this happen without any data-changing instructions ?  In other words can 
I get this fault using only _open, ATTACH and lots of SELECT commands until 
something falls over ?  Or even just repeated _open, ATTACH and _close until 
something falls over ?

No data on this question.  The purpose of this querty setup
is to copy some data into an auxialiary database.

 Note that the main database, which is updated periodically, doesn't have
 a corruption problem,

Are both 'main' and 'auxiliary' on in the same folder, being accessed the same 
way ?

Yes.  And significantly, there is no corruption problem with simultaneous
updates to the main database.


 and that this is only a problem with databases resident
 on a mac.  The same scenario, with databases resident on the PC disk, works
 fine.

When the databases are on the PC disk, what protocol is the Mac using to 
access them ?

Presumably the same.  Before recent versions of OSX this kind of access
used samba server.


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


[sqlite] SIGSEGV on INSERT DEFAULT VALUES with triggers

2010-03-24 Thread Tomasz Ł . Nowak
Hi!

A bug resulting in a crash (segmentation fault) of sqlite3 has been
detected. Please find attached the script causing problems and a debug
session log.

Tested to be vulnerable:
linux 3.6.23
linux 3.6.22
linux 3.6.4
solaris 3.5.1

Tested to be invulnerable:
linux 2.8.17

Best wishes
Tomasz Nowak
/tmp/sqlite-3.6.23 CFLAGS=-O0 -ggdb ./configure 
/tmp/sqlite-3.6.23 make
/tmp/sqlite-3.6.23 export LD_PRELOAD=.libs/libsqlite3.so
/tmp/sqlite-3.6.23 gdb .libs/sqlite3
Reading symbols from /tmp/sqlite-3.6.23/.libs/sqlite3...done.
(gdb) r -init script.sql
[Thread debugging using libthread_db enabled]
-- Loading resources from script.sql

___
 eax: ebx:B7FDDA10  ecx:0008  edx:0007 eflags:00010246
 esi:0804FE90 edi:080496E0  esp:BFFFD8F0  ebp:BFFFDA28 eip:B7F9D0A7
 cs:0073  ds:007B  es:007B  fs:  gs:0033  ss:007Bo d I t s Z a P c 
[007B:BFFFD8F0]-[stack]
BFFFD920 : B8 35 05 08  00 00 00 00 - FC 03 00 00  D8 4C 06 08 .5...L..
BFFFD910 : 00 00 00 00  10 DA FD B7 - 48 D9 FF BF  AD A3 F6 B7 H...
BFFFD900 : 00 00 00 00  B8 35 05 08 - F8 35 05 08  00 00 00 00 .5...5..
BFFFD8F0 : C8 45 06 08  07 00 00 00 - FF FF FF FF  07 00 00 00 .E..
[007B:0804FE90]-[ data]
0804FE90 : 55 89 E5 57  56 53 E8 4F - 00 00 00 81  C3 75 22 00 U..WVS.O.u.
0804FEA0 : 00 83 EC 0C  E8 1B 93 FF - FF 8D BB F0  FE FF FF 8D 
[0073:B7F9D0A7]-[ code]
0xb7f9d0a7 sqlite3Insert+3613:mov0xc(%eax),%esi
0xb7f9d0aa sqlite3Insert+3616:mov-0xac(%ebp),%edx
0xb7f9d0b0 sqlite3Insert+3622:mov%edx,%eax
0xb7f9d0b2 sqlite3Insert+3624:shl$0x2,%eax
0xb7f9d0b5 sqlite3Insert+3627:add%edx,%eax
0xb7f9d0b7 sqlite3Insert+3629:shl$0x2,%eax
--
0xb7f9d0a7 in sqlite3Insert (pParse=0x8064cd8, pTabList=0x8060358, pList=0x0, 
pSelect=0x0, pColumn=0x0, onError=0x63) at sqlite3.c:75798
75798   sqlite3ExprCodeAndCache(pParse, pList-a[j].pExpr, regCols+i+1);
(gdb) bt
#0  0xb7f9d0a7 in sqlite3Insert (pParse=0x8064cd8, pTabList=0x8060358, 
pList=0x0, pSelect=0x0, pColumn=0x0, onError=0x63) at sqlite3.c:75798
#1  0xb7fba1a2 in yy_reduce (yypParser=0x8065090, yyruleno=0xaf) at 
sqlite3.c:94450
#2  0xb7fbbef8 in sqlite3Parser (yyp=0x8065090, yymajor=0x16, yyminor=..., 
pParse=0x8064cd8) at sqlite3.c:95184
#3  0xb7fbcaad in sqlite3RunParser (pParse=0x8064cd8, zSql=0x8061598 INSERT 
INTO current DEFAULT VALUES ('a', 'b', 30);, pzErrMsg=0xbfffdc30) at 
sqlite3.c:96010
#4  0xb7fa45c8 in sqlite3Prepare (db=0x80531d0, zSql=0x8061598 INSERT INTO 
current DEFAULT VALUES ('a', 'b', 30);, nBytes=0x, saveSqlFlag=0x1, 
pReprepare=0x0, ppStmt=0xbfffdd1c, pzTail=0xbfffdd18) at sqlite3.c:79988
#5  0xb7fa4909 in sqlite3LockAndPrepare (db=0x80531d0, zSql=0x8061598 INSERT 
INTO current DEFAULT VALUES ('a', 'b', 30);, nBytes=0x, 
saveSqlFlag=0x1, pOld=0x0, ppStmt=0xbfffdd1c, pzTail=0xbfffdd18) at 
sqlite3.c:80083
#6  0xb7fa4ac1 in sqlite3_prepare_v2 (db=0x80531d0, zSql=0x8061598 INSERT INTO 
current DEFAULT VALUES ('a', 'b', 30);, nBytes=0x, ppStmt=0xbfffdd1c, 
pzTail=0xbfffdd18) at sqlite3.c:80158
#7  0x0804b452 in shell_exec (db=0x80531d0, zSql=0x8061598 INSERT INTO current 
DEFAULT VALUES ('a', 'b', 30);, xCallback=0x804a361 shell_callback, 
pArg=0xbfffde78, pzErrMsg=0xbfffddd4) at shell.c:990
#8  0x0804ef31 in process_input (p=0xbfffde78, in=0x8053008) at shell.c:2236
#9  0x0804f28b in process_sqliterc (p=0xbfffde78, sqliterc_override=0xb5f4 
script.sql) at shell.c:2370
#10 0x0804f6af in main (argc=0x3, argv=0xb454) at shell.c:2508

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


Re: [sqlite] hello.. I have some question for sqlite3..

2010-03-24 Thread D. Richard Hipp

On Mar 24, 2010, at 7:44 PM, 김민수 wrote:

 hello..
 I'm a student in Korea who study Database systems.
 I have some question for you.
 It is important for me so eventhen you are busy plz teach me about  
 some question..

 I would like to use sqlite3 with eclipse and mingw.
 Actually I have to use rtree moudle but i don't know how to complie..
 I already did some steps.
 In linux, I made source file after executing  : ../configure - make
 Sqlite3 works well with importing and compling in windows eclipse  
 environment.
 After then , i execute  -DSQLITE_ENABLE_RTREE=1  in linux's  
 makefile as option.
 but ater using rtree I can see these message.. : no such rtree  
 module..

 - create virtual table test using rtree (a,b,c,d,e);
: no such module : rtree

 The reason why I bring the file in linux is I already know Parser  
 doesn't be made in windows environment..

I suggest you use the SQLite amalgamation.  
http://www.sqlite.org/amalgamation.html 
   Either download a prebuilt amalgamation source file from the  
website, or else type

 make sqlite3.c

on Linux.  Then move the files sqlite3.c and sqlite3.h over to windows  
and compile them there together with -DSQLITE_ENABLE_RTREE.


 How can I use sqlite3 in windows eclipse environment..?
 I have to use eclipse in windows.
 I really thank for you it you teach me How to use sqlite's rtree in  
 detail..

 thank you..
 I look forward to your enswer..








D. Richard Hipp
d...@hwaci.com



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


[sqlite] BUG: Sqlite 3.6.23. Optimizer does not use indexes when a table is joined with a fts3 table

2010-03-24 Thread Shopsland gmail
### BUG: Sqlite 3.6.23. Optimizer does not use indexes when a table is
joined with a fts3 table

Given those two tables:

Table a
. number: integer primary key
. date: double (julian)
. index: dateindx (index of column date)
Total rows: 37866

Table fts (fts3 table)
. title: string
Total rows: 37866


### PROBLEM

With Sqlite 3.6.17 the following query executes in 12ms.

---
SELECT a.number
FROM a, fts
WHERE
a.number=fts.docid
ORDER BY a.date desc
LIMIT 20
---


With Sqlite version 3.6.23 the same query executes in *3238ms*.

When you join a table with a fts3 table, Sqlite 3.6.23 do not use
indexes, including the primary key.

You can partially solve this using 'indexed by'. It will work for one
index on table 'a' but not for both.

This select executes again in 12ms:

---
SELECT a.number
FROM a INDEXED BY dateindx, fts
WHERE
a.number=fts.docid
ORDER BY a.date desc
LIMIT 20
---


But if you add to this select statement a condition with 'number', the
primary key, the index for this column will not be used.

With versions 3.6.17 the following query executes in 9ms. With version
3.6.23 it executes in 175ms:

---
SELECT a.number
FROM a INDEXED BY dateindx, fts
WHERE
a.number=fts.docid
and a.number1000
ORDER BY a.date desc
LIMIT 20
---


Thanks for this great tool.

Keep up the good work!

Greetings! :-)

Jochi Martínez
www.bfreenews.com
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] corruption problem with attached macintosh database

2010-03-24 Thread Shane Harrelson
On Wed, Mar 24, 2010 at 7:20 PM, Dave Dyer ddyer-sql...@real-me.net wrote:


 
 Could you help us by adding any of the following details ?
 
 What OS is the Mac running ?

 OSX 10.4.11 for me, but also snow leopard.

 What OS is the PC running ?

 Windows 2003 server for me, but also XP (note the file systems are all mac
 file systems)

 What protocol is being used to access the Mac file share ?

 Presumably windows standard file sharing protocol over tcp

 Is the file-sharing host accessing the database as a shared file, or as a
 file on its hard disk ?

 The mac acting as file host is accessing the file as a local file.


 Does this happen without any data-changing instructions ?  In other words
 can I get this fault using only _open, ATTACH and lots of SELECT commands
 until something falls over ?  Or even just repeated _open, ATTACH and _close
 until something falls over ?

 No data on this question.  The purpose of this querty setup
 is to copy some data into an auxialiary database.

  Note that the main database, which is updated periodically, doesn't have
  a corruption problem,
 
 Are both 'main' and 'auxiliary' on in the same folder, being accessed the
 same way ?

 Yes.  And significantly, there is no corruption problem with simultaneous
 updates to the main database.


  and that this is only a problem with databases resident
  on a mac.  The same scenario, with databases resident on the PC disk,
 works
  fine.
 
 When the databases are on the PC disk, what protocol is the Mac using to
 access them ?

 Presumably the same.  Before recent versions of OSX this kind of access
 used samba server.




What journaling mode are you using?
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Pagesize and performance

2010-03-24 Thread Tom Broadbent
mainly just want to summarize and get confirmation on a few points.


1.   matching pagesize to file system record size is recommended for write 
performance improvements

2.   default SQLite pagesize is 1k; max SQLite pagesize is 32k

3.   docs seem to say that 32k max pagesize is no longer required, i.e. 
could possibly compile w/ larger max pagesize (and thus larger pagesize)

4.   larger pagesize will cause more data to be read from file system to do 
a read (i.e. an entire page must be read)

thanks
tom

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SIGSEGV on INSERT DEFAULT VALUES with triggers

2010-03-24 Thread Shane Harrelson
Can you provide more details?
What options are you using?
What version of the source? Amalgamation?  Preprocessed?  Complete package?

I could not reproduce this on the current or 3.6.23 build:

./sqlite3 -version
3.6.23

cat script.sql
CREATE TABLE current(x,y,z);
INSERT INTO current DEFAULT VALUES ('a', 'b', 30);

./sqlite3 -init script.sql
-- Loading resources from script.sql
Error: near line 2: near (: syntax error

If you are using the amalgamation or other pre-processed sources, you should
view the warnings at
   http://www.sqlite.org/compile.html#omitfeatures

Trying to OMIT or ENABLE features with compile options without using the
canonical sources can lead to issues like you are seeing.

HTH.
-Shane


2010/3/24 Tomasz Ł. Nowak tomasz.no...@man.poznan.pl

 Hi!

 A bug resulting in a crash (segmentation fault) of sqlite3 has been
 detected. Please find attached the script causing problems and a debug
 session log.

 Tested to be vulnerable:
 linux 3.6.23
 linux 3.6.22
 linux 3.6.4
 solaris 3.5.1

 Tested to be invulnerable:
 linux 2.8.17

 Best wishes
 Tomasz Nowak

 ___
 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] corruption problem with attached macintosh database

2010-03-24 Thread Dave Dyer



What journaling mode are you using?

whatever is default.  I compile mu own sqlite static libraries, but
I don't customize the settings.

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


Re: [sqlite] Update problem in use C/C++ interface

2010-03-24 Thread 王志刚
??? wrote:
 Hi, I meet a problem in use c/c++ API to update a row in table.
 all return value means the operate is successful, But the row have no
 change at all.

How do you determine this?

 the main code al follow:

wstring sql = LUPDATE Mail SET [Content] = ?1 [CurrentSize] = ?2
 WHERE [MailID] = ?3;;

There should be a comma after ?1.

Are you sure there actually exists a record with the ID you bind for
the third parameter? Note that, if there isn't, you won't get any
errors - the statement simply won't update any rows.

sqlite3_stmt *pstmt = NULL;
const char *pzTail = 0;
int nRes = SQLITE_OK;
nRes = sqlite3_prepare16_v2((sqlite3*)pDB, (void**)sql.c_str(),
 sizeof(wchar_t) * sql.length(), pstmt, 0);

Why do you need to cast pDB? What type is it declared with?

The second parameter of sqlite3_prepare16_v2 is const void*, not
void**. Your cast looks strange, though harmless. You shouldn't need
any cast at all.
--
Igor Tandetnik




about the comma after ?1. is a mistake when i paste code into mail. I
simplify some code, so miss the comma.
and i'm sure there is a record with the ID bind for the third parameter.
and the cast pDB,it's no matter.our interface declear is as void*.
-- 
 Thanks!
王志刚
---
电话:021-62672000-2852
上海圣诺网络技术有限公司
---
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] regression in FTS3 offsets function in 3.6.23

2010-03-24 Thread Dan Kennedy

On Mar 24, 2010, at 7:24 PM, Andrew Sutherland wrote:



 As reported on https://bugzilla.mozilla.org/show_bug.cgi?id=551260#c17
 The binaries used below were all downloaded from sqlite.org.

 $ cat fts3-offsets-asplode.sql
 CREATE VIRTUAL TABLE ft USING fts3(tokenize=porter, fulltextOne,  
 fulltextTwo);
 INSERT INTO ft VALUES(, foo);
 INSERT INTO ft VALUES(foo, foo);
 SELECT offsets(ft) FROM ft WHERE ft MATCH foo;

 $ sqlite3-3.6.22  fts3-offsets-asplode.sql
 1 0 0 3
 0 0 0 3 1 0 0 3

 $ sqlite3-3.6.23  fts3-offsets-asplode.sql
 Error: near line 4: database disk image is malformed

 My investigation thus far has identified the sqlite3Fts3Offsets  
 implementation as the
 source of the error.  It seems upset that the first column contains  
 an empty
 string and the tokenizer returns SQLITE_DONE.

It's a bug alright. Now fixed here:

   http://www.sqlite.org/src/ci/d37034f7fc

Thanks for working on this.

Dan.

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


Re: [sqlite] Updated FTS3 compression patch

2010-03-24 Thread Alexandre Courbot
 Patch is here
 http://sqlite.mobigroup.ru/src/vinfo/d3d9906674

Would love to try it - but for some reason I cannot find a way to get
an actual patch on this page. Could you produce a diff that could be
applied on top of 2.6.23's source, or even better amalgamation?

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