Re: [sqlite] Accessing SQLite from PHP5?

2010-05-18 Thread Michal Seliga
I think this is not really sqlite related, i am using fastcgi with nginx
server and when security became in issue i had similar problems
quick solution - do 'chmod -R 777  /srv/www' and you will see if problem
is related to rights or if its something else

also i think you should use absolute paths, or make sure that active
directory is set where you need. my cgi scripts run for user www-data
and active directory was set to /var/www and not to script location

On 18. 5. 2010 15:49, Gilles Ganault wrote:
> On Tue, 18 May 2010 14:30:06 +0100 (BST), Swithun Crowe
>  wrote:
>   
>> If you use PDO, then you get access to Sqlite 3.x databases:
>>
>> http://www.php.net/manual/en/ref.pdo-sqlite.php
>> 
> Thanks for the input. After following the following article, I
> successfully installed Lighttpd in FastCGI mode + PHP5 and PDO to
> access SQLite:
>
> www.kernelhardware.org/lighttpd-and-php/
>
> I'm having a problem, though, writing to a SQLite database located in
> Lighttpd's www directory (/srv/www/lighttpd).
>
> Could it be that the Www directory is off-limit to PHP scripts in
> write mode? FWIW, PDO can succesfully find and open db.sqlite:
> =
> 
> try {
> #TEST $dbh = new PDO("sqlite:./doesnt.exist.sqlite");
> #SQLSTATE[HY000] [14] unable to open database file
>
> #$dbh = new PDO("sqlite:./db.sqlite");
> $dbh->exec("CREATE TABLE IF NOT EXISTS customer (id INTEGER
> PRIMARY KEY, name VARCHAR(255))");
> $dbh->exec("INSERT INTO customer VALUES (NULL,'Dummy')");
> $dbh = null;
>
> print "Done";
>
> } catch(PDOException $e) {
> echo $e->getMessage();
> }
>
> ?>
> =
>
> After running this script, the browser simply displays "Done", but
> db.sqlite is 0-byte :-/
>
> FYI, here's what I tried after successfully installing Lighttpd +
> Lighttpd-fastci + PHP5 + PDO:
> =
> # pwd
> /srv/www/lighttpd
>
> # ll
> total 8
> -rw-r--r-- 1 root root   0 May 18 15:27 db.sqlite
> -rw-r--r-- 1 root root  20 May 18 15:15 info.php
> -rw-r--r-- 1 root root 646 May 18 15:34 sqlite.php
>
> # chown lighttpd.lighttpd ./*
>
> 
> http://localhost/sqlite.php:
> "Done"
>
> # ll
> total 8
> -rw-r--r-- 1 lighttpd lighttpd   0 May 18 15:27 db.sqlite
> -rw-r--r-- 1 lighttpd lighttpd  20 May 18 15:15 info.php
> -rw-r--r-- 1 lighttpd lighttpd 298 May 18 15:37 sqlite.php
> =
>
> Any idea what it could be? Could it be because I'm using the FastCGI
> mode?
>
> Thank you for any hint.
>
> ___
> 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] values containing dash - not evaluated

2010-04-26 Thread Michal Seliga
i had similar problems and it was caused by microsoft office
it didn't used ordinary dash but some strange character with different
ascii code - so search based on it always failed
i had to convert these strange dashes to ordinary ones to make it work
try, maybe this is also your case


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


Re: [sqlite] Problem with between clause and dates

2010-03-17 Thread Michal Seliga


On 17. 3. 2010 11:49, Mike Martin wrote:
> sample time= 2010-03-16 23:06:00
> sample start= 2010-03-16-22:00:00
> sample end= 2010-03-16 23:05:00
> select tsid from recordings where '2010-03-16 23:05:00' between start and end'
>
> This query should return nothing, so can anyone explain why it is
> recording the tsid
>
> thanks
>
>   

as far as i know  XX BETWEEN YY AND ZZ is equal to XX>=YY and XX<=ZZ so
its ok that it returns something. i always use it like that (but on
Sybase database)

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


Re: [sqlite] how to load custom function from QT

2010-01-25 Thread Michal Seliga
i somehow skipped one message in thread and as result i posted you what you
already knew and wrote, sorry  no more ideas from me


On 25. 1. 2010 12:27, greensparker wrote:
> 
> Thnks michel for ur reply.
> yes thats the way. i also tried using the HANDLE. but the query failed in
> int b = sqlite3_load_extension(handle,zFilename,0,0);
> my program hangs when i put 0,0 to the third and forth parameter in
> sqlite3_load_extension funciton.
> any tips?
> Thnks
> Bala
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] how to load custom function from QT

2010-01-25 Thread Michal Seliga
i did it, and solution is not nice
in general, qt doesn't export any of sqlitefunctions in its sqlite driver. so
you have to add sqlite to your project. you can find version of sqlite used in
qt in its sources (qt/src/3rdparty/sqlite) or if its set to use dynamically
sqlite installed in system you will have to link with it

then you can obtain sqlite handler using handle method of QSqlDriver class.
following is copied from qt docs:

 QSqlDatabase db = ...;
 QVariant v = db.driver()->handle();
 if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")==0) {
 // v.data() returns a pointer to the handle
 sqlite3 *handle = *static_cast(v.data());
 if (handle != 0) { // check that it is not NULL
 ...
 }
 }

then you can use sqlite3 *handle and call sqlite functions (which will be taken
from source/library you linked to project in addition to qt driver, but using qt
connection)

in general its not nice, but it works... nicer way would be to create custom qt
sqlite driver whcih would dowhat you and package it with your program, then you
will not have to have sqlite twice. but i didn't tried this approach so far


On 25. 1. 2010 11:42, greensparker wrote:
> 
> can somebody help me to solve this?
> 
> Bala
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Problems with SQLite under Cygwin

2009-10-20 Thread Michal Seliga
just an idea - make sure you are crosscompiling and libsqlite3.a is for
arm-linux and not for cygwin

j.hermanussen wrote:
> Hi to all, I'm new on this list.
> 
> I'm working on an application that runs on a small ARM-LINUX device, too 
> small to contain GCC. So I've installed Cygwin on my Win XP desktop PC. 
> Cygwin has arm-linux.gcc installed. Compiling & link works fine. The 
> exec is FTP'd to the ARM device. Works great.
> Now I want to incorporate SQLite in my application. I unzipped it to a 
> directory under Cygwin, did the configure, make & make install steps. 
> The library libsqlite3.a is in place but when I make a small main.c with 
> a call to sqlite3_open(...) in it, the linker says:
> undefined reference for sqlite3_open
> 
> Does anybody have any idea on what causes this link error?
> 
> Thanks for your attention,
> John
> 
> ___
> 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] Will Bitwise Operations Use an Index?

2009-10-09 Thread Michal Seliga


Pavel Ivanov wrote:
>>  change your query a bit when you use bitwise operations, in your case when 
>> you
>> have 'AND col_c&32' you may add 'AND col_c>=32'. now index will be used
> 
> col_c = 64 does pass second condition and doesn't pass first one. ;-)
> Bitwise operators cannot be changed so easily to inequalities.
> 
i didn't said this condition should be *replaced* , i said that inequality
should be *added*. then index could limit resultset, but bitwise operator will
still be used, only on hopefully smaller set of data

> 
> Pavel
> 
> On Fri, Oct 9, 2009 at 8:19 AM, Michal Seliga  
> wrote:
>>
>> Daniel Wickes wrote:
>>> I'm trying to optimise some of my queries, and I would like to know if
>>> bitwise operators in terms will still use an index, or if I should be
>>> thinking about moving the more important values to separate columns that
>>> could be checked for equality.
>>>
>>> At the moment, I have an index created much like:
>>>
>>> CREATE INDEX table_idx ON table(col_a,col_b,col_c);
>>>
>>> And then I am performing a query such as:
>>>
>>> SELECT count(*) FROM table WHERE col_a = 'apple' AND col_b = 3 AND col_c
>>> & 32;
>>>
>>> The key bit, if you'll pardon the pun, being the bitwise -and on col_c.
>>> Will this be using the index or will it be checking the table rows?
>>>
>>> Any help is much appreciated.
>>  change your query a bit when you use bitwise operations, in your case when 
>> you
>> have 'AND col_c&32' you may add 'AND col_c>=32'. now index will be used, but 
>> it
>> only makes sense if there is not too much rows where col_c>=32. you can use 
>> this
>> optimalisation always, it shouldn't slow down things, but real effect will 
>> work
>> only for higher bits. also in cases when you make bitwise & with more bits, 
>> you
>> can add >= condition only for lowest expected bit.
>>
>>> Many thanks,
>>>
>>> -- Dan
>>> ___
>>> 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] Will Bitwise Operations Use an Index?

2009-10-09 Thread Michal Seliga


Daniel Wickes wrote:
> I'm trying to optimise some of my queries, and I would like to know if
> bitwise operators in terms will still use an index, or if I should be
> thinking about moving the more important values to separate columns that
> could be checked for equality.
> 
> At the moment, I have an index created much like:
> 
> CREATE INDEX table_idx ON table(col_a,col_b,col_c);
> 
> And then I am performing a query such as:
> 
> SELECT count(*) FROM table WHERE col_a = 'apple' AND col_b = 3 AND col_c
> & 32;
> 
> The key bit, if you'll pardon the pun, being the bitwise -and on col_c.
> Will this be using the index or will it be checking the table rows?
> 
> Any help is much appreciated.

  change your query a bit when you use bitwise operations, in your case when you
have 'AND col_c&32' you may add 'AND col_c>=32'. now index will be used, but it
only makes sense if there is not too much rows where col_c>=32. you can use this
optimalisation always, it shouldn't slow down things, but real effect will work
only for higher bits. also in cases when you make bitwise & with more bits, you
can add >= condition only for lowest expected bit.

> 
> Many thanks,
> 
> -- Dan
> ___
> 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] STL and SQLite

2009-09-08 Thread Michal Seliga
Atul_Vaidya wrote:
> Hi,
> How to store a multimap in SQlite database ?
> My requirement is that i want to store a multimap in a column of
> the SQlite table
> Regards,
> Atul

i don't use stl but i also work with more complex structures.
the best approach to save them in database is  encode it to text or binary
field. in binary field its simpler to do and it saves space. working with text
is sometimes simpler in database operations, but you have to use some additional
encoding (base64, bintohex, uuencode/uudecode, whatever you want) to make sure
that stored text is pure ASCII and content won't be damaged
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Performance issue on records retrieval :: 100, 000 records

2009-07-16 Thread Michal Seliga


MADHAVAN VINOD wrote:
> 
> 5) No INDEX created.
> 
> The retrieval logic is such that to retrieve the oldest 10 records along
> with some additional constraints (say a, b and c are columns and the
> constraints are like a=1 AND b < c).  
> 
>  
> 
> So my WHERE clause is like  "CurrTime <= ExpireTime AND CurrTime >=
> NextProcessingTime AND a=1 AND b < c"
> 
> And my ORDER BY clause is " CurrTime - NextProcessingTime DESC, b ASC"
> 
>  
> 
>  


you need index for this, otherwise lookup goes through whole table
question is what index would help you the most.

if you always have condition a=1 (or something similar which uses = for
comparison) you should have index which starts with this field.

now i am not sure if i understood you correctly, are ExpireTime and
NextProcessingTime database fields? if yes, then in addition you should have at
the end of index columns one of ExpireTime or NextProcessingTime, you should
choose one which can help you more (one which will help database engine to limit
row count the most)

so for situation you wrote i would recommend to have one of indices:
create index ... on ...(a,ExpireTime)
or

create index ... on ...(a,NextProcessingTime )
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Do people think of SQLite as a file or as a database

2009-07-16 Thread Michal Seliga
for me sqlite is database engine. and its files i call databases

CadMapper wrote:
> This is not a technical question about SQLite.  I want to you how people in
> general think about SQLite.  Is that a file or a database?  When you talk
> about it, do you refer to it as file or database?
> 
> Thanks for your input in advance!
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] what is most effective way to temporarily disable triggers?

2009-07-09 Thread Michal Seliga
hi

attached is patch which will make temporary disable of triggers possible. i
tried it in my application with current data (many inserts in to various table
with many triggers on them, which are not meant to be run while importing data).
it works and it changed running time from 62 seconds to 4, so i guess its worth 
it

i added new pragma DISABLE_TRIGGERS which can be set to 0 (default, everything
works) or 1 (function which returns triggers always returns empty list so none
will be called)

honestly, i didn't spent too much time with learning sqlite sources, i just made
quick hack which works for me, i hope i diidn't break anything. so i decided to
share it. maybe one day this feature can get to official version too



diff -r -u sqlite-3.6.16.orig/src/pragma.c sqlite-3.6.16/src/pragma.c
--- sqlite-3.6.16.orig/src/pragma.c 2009-06-25 13:45:58.0 +0200
+++ sqlite-3.6.16/src/pragma.c  2009-07-09 12:16:06.31250 +0200
@@ -1388,6 +1388,10 @@
   }else
 #endif
 
+  if( sqlite3StrICmp(zLeft, "DISABLE_TRIGGERS")==0 ){
+  db->isDisabledTriggers=(u8)atoi(zRight);
+  }
+  else
  
   {/* Empty ELSE clause */}
 
diff -r -u sqlite-3.6.16.orig/src/sqliteInt.h sqlite-3.6.16/src/sqliteInt.h
--- sqlite-3.6.16.orig/src/sqliteInt.h  2009-06-26 17:14:56.0 +0200
+++ sqlite-3.6.16/src/sqliteInt.h   2009-07-09 12:16:10.46875 +0200
@@ -869,6 +869,7 @@
   void (*xUnlockNotify)(void **, int);  /* Unlock notify callback */
   sqlite3 *pNextBlocked;/* Next in list of all blocked connections */
 #endif
+  u8 isDisabledTriggers;/* True if triggers should be disabled */
 };
 
 /*
diff -r -u sqlite-3.6.16.orig/src/trigger.c sqlite-3.6.16/src/trigger.c
--- sqlite-3.6.16.orig/src/trigger.c2009-06-25 13:35:52.0 +0200
+++ sqlite-3.6.16/src/trigger.c 2009-07-09 12:17:11.15625 +0200
@@ -50,6 +50,9 @@
   Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
   Trigger *pList = 0;  /* List of triggers to return */
 
+  if(pParse->db->isDisabledTriggers)
+ return (Trigger *)0;
+
   if( pTmpSchema!=pTab->pSchema ){
 HashElem *p;
 for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] what is most effective way to temporarily disable triggers?

2009-07-09 Thread Michal Seliga
hi

attached is patch which will make temporary disable of triggers possible. i
tried it in my application with current data (many inserts in to various table
with many triggers on them, which are not meant to be run while importing data).
it works and it changed running time from 62 seconds to 4, so i guess its worth 
it

i added new pragma DISABLE_TRIGGERS which can be set to 0 (default, everything
works) or 1 (function which returns triggers always returns empty list so none
will be called)

honestly, i didn't spent too much time with learning sqlite sources, i just made
quick hack which works for me, i hope i diidn't break anything. so i decided to
share it. maybe one day this feature can get to official version too


diff -r -u sqlite-3.6.16.orig/src/pragma.c sqlite-3.6.16/src/pragma.c
--- sqlite-3.6.16.orig/src/pragma.c 2009-06-25 13:45:58.0 +0200
+++ sqlite-3.6.16/src/pragma.c  2009-07-09 12:16:06.31250 +0200
@@ -1388,6 +1388,10 @@
   }else
 #endif
 
+  if( sqlite3StrICmp(zLeft, "DISABLE_TRIGGERS")==0 ){
+  db->isDisabledTriggers=(u8)atoi(zRight);
+  }
+  else
  
   {/* Empty ELSE clause */}
 
diff -r -u sqlite-3.6.16.orig/src/sqliteInt.h sqlite-3.6.16/src/sqliteInt.h
--- sqlite-3.6.16.orig/src/sqliteInt.h  2009-06-26 17:14:56.0 +0200
+++ sqlite-3.6.16/src/sqliteInt.h   2009-07-09 12:16:10.46875 +0200
@@ -869,6 +869,7 @@
   void (*xUnlockNotify)(void **, int);  /* Unlock notify callback */
   sqlite3 *pNextBlocked;/* Next in list of all blocked connections */
 #endif
+  u8 isDisabledTriggers;/* True if triggers should be disabled */
 };
 
 /*
diff -r -u sqlite-3.6.16.orig/src/trigger.c sqlite-3.6.16/src/trigger.c
--- sqlite-3.6.16.orig/src/trigger.c2009-06-25 13:35:52.0 +0200
+++ sqlite-3.6.16/src/trigger.c 2009-07-09 12:17:11.15625 +0200
@@ -50,6 +50,9 @@
   Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
   Trigger *pList = 0;  /* List of triggers to return */
 
+  if(pParse->db->isDisabledTriggers)
+ return (Trigger *)0;
+
   if( pTmpSchema!=pTab->pSchema ){
 HashElem *p;
 for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] migrating a pipeline to using sqlite

2009-07-07 Thread Michal Seliga


Robert Citek wrote:

> create table foo (
>  col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9,
>  col_10, col_11, col_12, col_13, col_14, col_15, col_16, col_17,
>  col_18, col_19, col_20, col_21, col_22 ) ;
> .mode tab
> .imp "foo.tsv" "foo"
> select col_9, col_22, count(*) as "count" from foo group by col_9, col_22 ;

Try this with index created on foo(col_9, col_22).
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] what is most effective way to temporarily disable triggers?

2009-06-24 Thread Michal Seliga


D. Richard Hipp wrote:
> On Jun 24, 2009, at 10:35 AM, Michal Seliga wrote:
>>> Instead of
>>>
>>> WHEN not exists(SELECT * FROM )
>>>
>>> create an application-defined function (perhaps called
>>> "enable_triggers()") that returns either 1 or 0 depending on the
>>> setting of some variable in your application.  Then use
>>>
>>> WHEN enable_triggers()
>>>
>>> The triggers will still launch, but calling an application-defined
>>> function takes much less time than running NOT EXISTS, so the  
>>> triggers
>>> will very quickly figure out that they should exit without doing
>>> anything.
>>>
>>>
>> strangely, it didn't helped, time is almost the same with not exists  
>> or with
>> your idea. actually with function its even a little bit worse
>>
> 
> 
> Are you reparsing every INSERT separately or are you creating a single  
> prepared statement and reusing it over and over?
> 
  for each table its prepared once and then reused, only new parameters are
filled in. pure query.exec() time is like this:
  without triggers: 0.766s
  with triggers which use not exist(): 2.438s
  with triggers which use function: 2.484s

(its measured by getting 2 times, one with exec() skipped and one when it
happens and subtract these times from each other)

as you can see pure exec() time is about 3x as long when triggers are used. and
if i use notexists() or function() doesn't make big difference (in fact it can
even be considered as measuring error)

btw all these times are from quite fast pc. but application is targeted to work
with much more data and on much slower device (windows mobile) with slow
filesystem. sample tests showd that what takes ~20 seconds on my pc is about 3.5
minutes on target device.

> 
> 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


Re: [sqlite] what is most effective way to temporarily disable triggers?

2009-06-24 Thread Michal Seliga


D. Richard Hipp wrote:
> On Jun 24, 2009, at 9:17 AM, Michal Seliga wrote:
> 
>> hi
>>
>> in my application i sometimes must insert huge amount of pre- 
>> prepared data so i
>> don't want triggers to do any action while i am inserting them
>>
>> for this reason i created one small table which is normally empty,  
>> however if it
>> contains record set to 1 triggers shoudl not do any action. to make  
>> this happen
>> i use triggers like this following example
>>
>> CREATE TRIGGER sync_Activity_oninsert after insert on Activity
>> for each row
>> when (not exists(select * from sync_block where sub_block=1))
>> begin
>>  --action
>> end;
>>
>> to block triggers i do: insert into sync_block values(1);
>> to enable them back i do: delete from sync_block;
>>
>>
>> this helped to stop triggers from doing any action, but they still  
>> launch and in
>> result import of data takes 2x more with triggers then without them.
>>
>> is there any other, faster, way to temporarily disable triggers?
>>
>> i found one more possibility, someone recommended it on this list in  
>> year 2005
>> that its possible to list all create trigger statements from  
>> database, drop
>> them, make action and recreate them back. this will work, but time  
>> for creating
>> so many triggers (yes, they are many) may be also very bad. in  
>> addition it
>> doesn't seem as very nice solution to me...
>>
>> the most prefered way for me would be to use some pragma to disable  
>> triggers,
>> but looking to documentation i wasn't able to find any...
>>
>> maybe someone has any other idea?
> 
> Instead of
> 
>  WHEN not exists(SELECT * FROM )
> 
> create an application-defined function (perhaps called  
> "enable_triggers()") that returns either 1 or 0 depending on the  
> setting of some variable in your application.  Then use
> 
>  WHEN enable_triggers()
> 
> The triggers will still launch, but calling an application-defined  
> function takes much less time than running NOT EXISTS, so the triggers  
> will very quickly figure out that they should exit without doing  
> anything.
> 
> 
strangely, it didn't helped, time is almost the same with not exists or with
your idea. actually with function its even a little bit worse

what i did was that i created custom function using:
sqlite3_create_function(handle,"enable_triggers",-1,SQLITE_ANY,NULL,enable_triggers,NULL,NULL)

and function enable_triggers is like this:
static int mEnableTriggers;
static void enable_triggers(sqlite3_context *context, int nieco, sqlite3_value
**value)
{
sqlite3_result_int(context,mEnableTriggers);
}

and global variable mEnableTriggers is set to 1 or to 0 depending on what i want
it do do.

yet sample test showed almost the same times as it was, with some little sample
data reults were:
without triggers: 3.766 seconds
with triggers which use not exists: 5.438 seconds
with triggers which use function: 5.484 seconds


this was time needed to insert ~25000 records to various tables so you can
imagine how it would be with more



>>
>>
>> ___
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 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] what is most effective way to temporarily disable triggers?

2009-06-24 Thread Michal Seliga
hi

in my application i sometimes must insert huge amount of pre-prepared data so i
don't want triggers to do any action while i am inserting them

for this reason i created one small table which is normally empty, however if it
contains record set to 1 triggers shoudl not do any action. to make this happen
i use triggers like this following example

CREATE TRIGGER sync_Activity_oninsert after insert on Activity
for each row
when (not exists(select * from sync_block where sub_block=1))
begin
--action
end;

to block triggers i do: insert into sync_block values(1);
to enable them back i do: delete from sync_block;


this helped to stop triggers from doing any action, but they still launch and in
result import of data takes 2x more with triggers then without them.

is there any other, faster, way to temporarily disable triggers?

i found one more possibility, someone recommended it on this list in year 2005
that its possible to list all create trigger statements from database, drop
them, make action and recreate them back. this will work, but time for creating
so many triggers (yes, they are many) may be also very bad. in addition it
doesn't seem as very nice solution to me...

the most prefered way for me would be to use some pragma to disable triggers,
but looking to documentation i wasn't able to find any...

maybe someone has any other idea?



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