Re: [sqlite] Making blob as a sqlite database.

2019-04-26 Thread Richard Hipp
On 4/26/19, Mohd Radzi Ibrahim  wrote:
> Hi, is there a vfs that could be used to open a blob column as a database?

I think you probably want the sqlite3_deserialize() interface.
https://www.sqlite.org/c3ref/deserialize.html

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


[sqlite] Making blob as a sqlite database.

2019-04-26 Thread Mohd Radzi Ibrahim
Hi, is there a vfs that could be used to open a blob column as a database?


thanks.

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


Re: [sqlite] Regarding sqlite3 reliability in using in service oriented architecture

2019-04-26 Thread Jens Alfke


> On Apr 25, 2019, at 6:09 PM, Lullaby Dayal  wrote:
> 
> A single database connection is shared
> among all these services. More than one service access the service API to
> read/write database at the same time. No locking is implemented in our
> service accessing the database.

The one issue that comes to mind is transactions: your design has no isolation 
(the I in ACID) between threads. 

In more detail: if a thread executes "BEGIN", does some 
inserts/updates/deletes, and then executes "END", other threads that issue 
SQLite calls at the same time will see the uncommitted changes being made by 
the first thread. Depending on your design, this can cause problems, especially 
if the first thread ever ends up aborting the transaction (leaving the other 
threads with stale data that isn't in the database.)

It gets even more "fun" if the secondary threads are making their own changes 
(without BEGIN/END), because those changes will become part of the first 
thread's transaction, so if the first thread aborts, the other threads' changes 
will be lost.

For this reason it's usually good to have a mutex for transactions: you lock 
the mutex before calling BEGIN and unlock it after calling END. (If you make 
one-off changes without BEGIN/END, you have to lock the mutex around those 
calls too.)

If this isn't a problem for you because you never use transactions, then you 
may have a different problem: write performance. Issuing multiple writes 
without a transaction is inefficient, because each write has to begin and 
commit its own transaction, and the commits tend to be expensive (depending on 
the filesystem) because they have to ensure durability.

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


[sqlite] Custom collation of blobs

2019-04-26 Thread Jens Alfke
We are using SQLite blobs to store some structured values, and need control 
over how they are collated in queries, i.e. memcmp is not the correct ordering. 
We’ve registered a custom collating function, but unfortunately it doesn’t get 
called. According to the docs, collating functions are only used to compare 
strings, not any other data type. Is there any way around this limitation?

The only workaround I can think of is to define a custom function that converts 
a blob to a string and collate using those strings — e.g. `… ORDER BY 
collatable_blob(b)`. But this requires expensive string conversions, and it 
doesn’t work well with indexes.

It would be much cleaner and more efficient if there were a type of collating 
function that operated on all data types.

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


Re: [sqlite] Debugging sqlite3.c

2019-04-26 Thread x
If I put this line at the top of sqlite3.c

#define SQLITE_DEBUG 1

should that be the same as setting SQLITE_DEBUG? I’ve tried it and the IDE 
still doesn’t add debug info for the sqlite3.c file.
From: x
Sent: 26 April 2019 13:23
To: SQLite mailing list
Subject: [sqlite] Debugging sqlite3.c

Could anyone give me an idiot’s guide on how to do this in the rad studio 10 
IDE? I’ve tried adding DEBUG_SQLITE to “Project | Options | C++ (Shared 
Options) | Conditional defines ... (for Debug configuration – 32 bit Windows 
platform)” but it doesn’t seem to work. Looked elsewhere in the Options but 
can’t find anywhere else to add the DEBUG_SQLITE directive.

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

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


Re: [sqlite] .expert output help

2019-04-26 Thread Dan Kennedy


On 26/4/62 23:56, Jose Isaias Cabrera wrote:

this query. If you try ".expert -verbose", it will tell you the other

This is the output from --verbose

sqlite> .expert --verbose
sqlite>  SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
...>  LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
...>  AND
...>  b.InsertDate =
...>  (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = 
ProjID)
...>  WHERE a.ProjID IN
...>  (
...>  SELECT a.ProjID FROM Project_List WHERE 1=1
...>  AND lower(a.Manager) LIKE '%diggs%'
...>  ) AND a.InsertDate =
...> (SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)
...>
...>  GROUP BY a.ProjID;
-- Candidates -
(null)
...

Maybe Candidates should say something else other than (null).


That means it couldn't even come up with anything to try - you already 
have indexes for all WHERE constraints an ORDER/GROUP BY terms in the 
query. It should probably say "(no candidates found)", or something 
along those lines.


Dan.



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


Re: [sqlite] .expert output help

2019-04-26 Thread Jose Isaias Cabrera
Dan Kennedy, on Friday, April 26, 2019 12:13 PM wrote...
>On 26/4/62 21:30, Jose Isaias Cabrera wrote:
>Hey! Somebody tried it out! Thanks! :)

I have been using it for a while. ;-)  I have been adding INDEXes for queries 
used a lot...

>this query. If you try ".expert -verbose", it will tell you the other

This is the output from --verbose

sqlite> .expert --verbose
sqlite>  SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
   ...>  LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
   ...>  AND
   ...>  b.InsertDate =
   ...>  (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = 
ProjID)
   ...>  WHERE a.ProjID IN
   ...>  (
   ...>  SELECT a.ProjID FROM Project_List WHERE 1=1
   ...>  AND lower(a.Manager) LIKE '%diggs%'
   ...>  ) AND a.InsertDate =
   ...> (SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)
   ...>
   ...>  GROUP BY a.ProjID;
-- Candidates -
(null)
-- Query 1 
SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
 LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
 AND
 b.InsertDate =
 (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = ProjID)
 WHERE a.ProjID IN
 (
 SELECT a.ProjID FROM Project_List WHERE 1=1
 AND lower(a.Manager) LIKE '%diggs%'
 ) AND a.InsertDate =
(SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)

 GROUP BY a.ProjID;

(no new indexes)

SCAN TABLE Project_List AS a USING INDEX ProjID_InsertDate
CORRELATED LIST SUBQUERY 2
SCAN TABLE Project_List USING COVERING INDEX Project_Name
CORRELATED SCALAR SUBQUERY 3
SEARCH TABLE Project_List USING COVERING INDEX ProjID_InsertDate (ProjID=?)
SEARCH TABLE Project_ABT_Budget AS b USING COVERING INDEX sqlite_autoindex_Proje
ct_ABT_Budget_1 (ProjID=?)
CORRELATED SCALAR SUBQUERY 1
SEARCH TABLE Project_ABT_Budget USING COVERING INDEX PAB_ProjIDInsertDateProjIDI
nsertDate (ProjID=?)

Maybe Candidates should say something else other than (null).


>schema (use the shell tool's ".schema" command). It makes it easier to

Yes, I know this should be broken down better, but this is a reporting tool 
that I am creating to quickly and fast report factual project data by importing 
exports from a system. Instead of Excel scripts, SQLite takes the imports, 
keeps track of the changes, makes smart reporting to users and provide process 
suggestions to prevent projects from getting outside their original baseline.  
So, if here is the .schema, Dan. ;-)

sqlite> .schema
CREATE TABLE PMData
(
  login primary key,
  email,
  FirstName,
  LastName,
  Address,
  City,
  State,
  Zip,
  WorkPhone,
  Intelnet,
  HomePhone,
  Password,
  ComputerName,
  UserProfilePath
, Beep, PMOHome, UseMailTo, SoundOff, UseLocalSharedDB, LastClarityUpdate, 
PMLocalDrive);
CREATE TABLE Master_Project_List_Extra
(
  ProjID PRIMARY KEY,
  PMONotes,
  CurrYear,
  PlanYear,
  KeyProj,
  PMOStatus
, BusApprDate, RepBoardDir, RepIberOpComm, Cost_Type, CompanyName, 
CurAgreedDel, InitPortYr, Department, FinancialStatus, FinancialType, 
Global_Local, WIP_Class, BusCaseVer, ITOpCo, InitAgreedEndDate, ChargeCode, 
ResOBSUnit, DepName, ITStrategy, Program, ResCode, Sponsor, InBusPlan, InPDS, 
InSubDept, LaunchRev, ALaborRes, CurAgrFinishDate, TimeIndiVal, TimeIndiColor, 
CostIndiVal, CostIndiColor, EstiDeliDate, PlannedProgess, ActualProgess, 
CommType, AnnualEACExt, BusCaseTotCost, AnnCostExt, EACTotCost, TimeMargin, 
ProgressDevVal, ProgressDevColor, CostDevVal, CostDevColor, EACExt, ActualsExt, 
EACvBusTotVal, EACvBusTotColor, EACvAnnPlanVal, EACvAnnPlanColor, EACvCBL, 
PlannedCostPcent, ActualCostPcent, TimevCBLKPIVal, TimevCBLKPIColor, 
AnnActualExt, AnnPlanCostPcent, ApprComDateTimeMargin, IncludedInPDS, IsActive, 
ProjCBLExt);
CREATE TABLE `Bus_IT_Areas_ORGs` (
`IT_OBS`TEXT NOT NULL UNIQUE,
`Area`  TEXT,
`Org`   INTEGER,
PRIMARY KEY(`IT_OBS`)
);
CREATE TABLE Business_OBS_List
(
Bus_OBS TEXT NOT NULL UNIQUE,
Bus_Area,
Bus_Org TEXT,
PRIMARY KEY(Bus_Area)
);
CREATE TABLE PMOTitles
(
  TitleKey PRIMARY KEY,
  Titles
);
CREATE TABLE Project_List
(
  ProjID,
  CID,
  Project_Name,
  PMO_Board_Report,
  Project_Type,
  Start_date,
  Target_Go_Live_Date,
  Finish_Date,
  BL_Start,
  BL_Finish,
  Tot_CapexP,
  CapexP_Cur,
  Tot_OpexP,
  OpexP_Cur,
  Manager,
  Status_Indicator,
  SI_Color,
  Progress,
  status_comment,
  State,
  Business_Owner,
  BRD,
  Business_priority,
  BP_Color,
  First_BL,
  Updated_By,
  Updated_Dt,
  Status,
  Baseline_Cost,
  Baseline_Cur,
  Baseline_Time,
  Active,
  PMO_Percentage,
  PMO_Request,
  Financial_Status,
  Ann_CapexP,
  Ann_OpexP,
  YTD_Ann_Capex,
  YTD_Ann_Opex,

Re: [sqlite] .expert output help

2019-04-26 Thread Dan Kennedy


On 26/4/62 21:30, Jose Isaias Cabrera wrote:

Greetings.

sqlite> .expert
sqlite>  SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
...>  LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
...>  AND
...>  b.InsertDate =
...>  (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = 
ProjID)
...>  WHERE a.ProjID IN
...>  (
...>  SELECT a.ProjID FROM Project_List WHERE 1=1
...>  AND lower(a.Manager) LIKE '%jic%'
...>  ) AND a.InsertDate =
...> (SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)
...>
...>  GROUP BY a.ProjID;
(no new indexes)

SCAN TABLE Project_List AS a USING INDEX ProjID_InsertDate
CORRELATED LIST SUBQUERY 2
SCAN TABLE Project_List USING COVERING INDEX Project_Name
CORRELATED SCALAR SUBQUERY 3
SEARCH TABLE Project_List USING COVERING INDEX ProjID_InsertDate (ProjID=?)
SEARCH TABLE Project_ABT_Budget AS b USING COVERING INDEX 
sqlite_autoindex_Project_ABT_Budget_1 (ProjID=?)
CORRELATED SCALAR SUBQUERY 1
SEARCH TABLE Project_ABT_Budget USING COVERING INDEX 
PAB_ProjIDInsertDateProjIDInsertDate (ProjID=?)

I have a few questions for the .experts :-),



Hey! Somebody tried it out! Thanks! :)


-- On line 5 of the resulted output ,

SCAN TABLE Project_List USING COVERING INDEX Project_Name

Why is it scanning the table using that INDEX if there is no "Project_Name" 
referenced in the query? That is one of the fields of Project_List, but it is not being 
used now.


There's either an error or a strange construction created by a program 
in this part of the query:


 WHERE a.ProjID IN
   ...>  (
   ...>  SELECT a.ProjID FROM Project_List WHERE 1=1
   ...>  AND lower(a.Manager) LIKE '%jic%'
   ...>  )


The sub-query scans table "Project_List", but doesn't use any columns 
from it (both a.ProjID and a.Manager are from the outer query). So, to 
do the scan, SQLite is choosing the index it thinks will require the 
minimum IO. i.e. one on very few fields.



-- How can I create the INDEX on line 8 that sqlite_autoindex created?


You have already done so. Index "sqlite_autoindex_Project_ABT_Budget_1" 
is actually a PRIMARY KEY or UNIQUE constraint within the definition of 
table "Project_ABT_Budget".


In this case, the key piece of output is "(no new indexes)". This means 
that ".expert" thinks you have already created the optimal indexes for 
this query. If you try ".expert -verbose", it will tell you the other 
indexes it considered. Or, if you run it on a version of your db that 
has no indexes at all, you can see that it will (hopefully!) recommend 
indexes equivalent to those you already have.


For posts like these, unless you're constrained by company rules or some 
other similar consideration, it's good to include the entire database 
schema (use the shell tool's ".schema" command). It makes it easier to 
answer questions regarding specific queries and allows people to 
recreate your experiment themselves if they wish to investigate further.


Dan.




Thanks for your knowledge sharing.

josé

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

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


Re: [sqlite] Regarding sqlite3 reliability in using in service oriented architecture

2019-04-26 Thread Jose Isaias Cabrera

> You will be hard-pressed to buy a new car these days that isn't
> running either QNX or Android or both.

Not my '73 Ford Maverick. :-)
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] .expert output help

2019-04-26 Thread Jose Isaias Cabrera

Simon Slavin on Friday, April 26, 2019 10:50 AM wrote...
>On 26 Apr 2019, at 3:30pm, Jose Isaias Cabrera  wrote:

>Once you have defined those indices, execute the ANALZE command, then try
>the .expert again.
Thanks.

>What led to you using WHERE 1=1 ?  An apparent bug ?
Long story. The app has many textboxes where the user can insert a string and 
hit ENTER and so a search is added to the query based on the textboxes that 
have data in them.  So, having WHERE 1=1 makes it easy to have other search 
additions by just doing,

AND (a.field_A LIKE %jic%)

and adding another one,

AND (b.field_B LIKE %something%)

etc., etc. So, in the end the query ends up being something like this,

 SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
 LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
 AND
 b.InsertDate =
 (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = ProjID)
 WHERE a.ProjID IN
 (
 SELECT a.ProjID FROM Project_List WHERE 1=1
 AND lower(a.Manager) LIKE '%diggs%'
 AND (a.field_A LIKE %jic%)
 AND (a.field_B LIKE %something%)
 ) AND a.InsertDate =
(SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)

 GROUP BY a.ProjID;

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


Re: [sqlite] Regarding sqlite3 reliability in using in service oriented architecture

2019-04-26 Thread Simon Slavin
On 26 Apr 2019, at 3:48pm, James K. Lowden  wrote:

> Am I the only one who reads a sentence like that and thinks, "I don't want to 
> drive that car"? 

Databases are used in black boxes (which every car has these days) and in 
infotainment and SatNav systems.  It might not be involved in a safety-critical 
system.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Regarding sqlite3 reliability in using in service oriented architecture

2019-04-26 Thread Richard Hipp
On 4/26/19, James K. Lowden  wrote:
> On Fri, 26 Apr 2019 02:09:33 +0100
> Lullaby Dayal  wrote:
>
>> We use sqlite3 in an embedded automotive system based on QNX
>> hypervisor running multiple virtual machines.
>
> Am I the only one who reads a sentence like that and thinks, "I don't
> want to drive that car"?

You will be hard-pressed to buy a new car these days that isn't
running either QNX or Android or both.
-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] .expert output help

2019-04-26 Thread Simon Slavin
On 26 Apr 2019, at 3:30pm, Jose Isaias Cabrera  wrote:

> -- On line 5 of the resulted output ,
> 
> SCAN TABLE Project_List USING COVERING INDEX Project_Name
> 
> Why is it scanning the table using that INDEX if there is no "Project_Name" 
> referenced in the query? That is one of the fields of Project_List, but it is 
> not being used now.

Since there is no ideal index it needs to scan the list using something.  That 
index seems to be fairly short and covers all the data needed, because all data 
can be retrieved directly from the index rather than needing an additional 
lookup in the table itself.

> -- How can I create the INDEX on line 8 that sqlite_autoindex created?

I think you mean

SEARCH TABLE Project_ABT_Budget AS b USING COVERING INDEX 
sqlite_autoindex_Project_ABT_Budget_1 (ProjID=?)

in which case the command is

CREATE INDEX myName1 ON Project_ABT_Budget (ProjID)

You should also do something like

CREATE INDEX myName2 ON Project_List (InsertDate)
CREATE INDEX myName3 ON Project_List (ProjID,InsertDate)

Once you have defined those indices, execute the ANALZE command, then try the 
.expert again.

What led to you using WHERE 1=1 ?  An apparent bug ?


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


Re: [sqlite] Regarding sqlite3 reliability in using in service oriented architecture

2019-04-26 Thread James K. Lowden
On Fri, 26 Apr 2019 02:09:33 +0100
Lullaby Dayal  wrote:

> We use sqlite3 in an embedded automotive system based on QNX
> hypervisor running multiple virtual machines. 

Am I the only one who reads a sentence like that and thinks, "I don't
want to drive that car"? 

I hope the embedded automotive system is in the garage, and not under
the hood.  

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


[sqlite] .expert output help

2019-04-26 Thread Jose Isaias Cabrera

Greetings.

I want to search the DB for all projects owned by "jic" and I have queried the 
DB with the following:
SQLite version 3.28.0 2019-04-16 19:49:53
Enter ".help" for usage hints.
sqlite> .expert
sqlite>  SELECT a.*,sum(b.AnnualDossier) as Dossier FROM Project_List AS a
   ...>  LEFT JOIN Project_ABT_Budget AS b ON a.ProjID = b.ProjID
   ...>  AND
   ...>  b.InsertDate =
   ...>  (SELECT MAX(InsertDate) FROM Project_ABT_Budget WHERE b.ProjID = 
ProjID)
   ...>  WHERE a.ProjID IN
   ...>  (
   ...>  SELECT a.ProjID FROM Project_List WHERE 1=1
   ...>  AND lower(a.Manager) LIKE '%jic%'
   ...>  ) AND a.InsertDate =
   ...> (SELECT MAX(InsertDate) FROM Project_List WHERE ProjID = a.ProjID)
   ...>
   ...>  GROUP BY a.ProjID;
(no new indexes)

SCAN TABLE Project_List AS a USING INDEX ProjID_InsertDate
CORRELATED LIST SUBQUERY 2
SCAN TABLE Project_List USING COVERING INDEX Project_Name
CORRELATED SCALAR SUBQUERY 3
SEARCH TABLE Project_List USING COVERING INDEX ProjID_InsertDate (ProjID=?)
SEARCH TABLE Project_ABT_Budget AS b USING COVERING INDEX 
sqlite_autoindex_Project_ABT_Budget_1 (ProjID=?)
CORRELATED SCALAR SUBQUERY 1
SEARCH TABLE Project_ABT_Budget USING COVERING INDEX 
PAB_ProjIDInsertDateProjIDInsertDate (ProjID=?)

I have a few questions for the .experts :-),

-- On line 5 of the resulted output ,

SCAN TABLE Project_List USING COVERING INDEX Project_Name

Why is it scanning the table using that INDEX if there is no "Project_Name" 
referenced in the query? That is one of the fields of Project_List, but it is 
not being used now.

-- How can I create the INDEX on line 8 that sqlite_autoindex created?

Thanks for your knowledge sharing.

josé

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


[sqlite] Debugging sqlite3.c

2019-04-26 Thread x
Could anyone give me an idiot’s guide on how to do this in the rad studio 10 
IDE? I’ve tried adding DEBUG_SQLITE to “Project | Options | C++ (Shared 
Options) | Conditional defines ... (for Debug configuration – 32 bit Windows 
platform)” but it doesn’t seem to work. Looked elsewhere in the Options but 
can’t find anywhere else to add the DEBUG_SQLITE directive.

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


[sqlite] Bug report: Segfault in sqlite3_clear_bindings when statement is nullptr

2019-04-26 Thread Christof Arnosti
Hi together,

I want to report a (possible) bug in sqlite3. When
sqlite3_clear_bindings is called with a nullptr argument, then a
SEGFAULT occurs.

From the behavior of the other methods which use statement as a
parameter I expected the behaviour that sqlite3_clear_bindings with a
nullptr argument is a no-op, since all of sqlite3_bind_*, sqlite3_step,
sqlite3_reset and sqlite3_finalize (that's the ones I checked) don't crash.

Please have a look at the example below.

#include  #include "sqlite3.h" sqlite3* db; int main()
{
// DB Setup sqlite3_open(":memory:", ); sqlite3_exec(db, "CREATE TABLE 
test (id INTEGER PRIMARY KEY);", nullptr, nullptr, nullptr); // Working example 
sqlite3_stmt* workingStatement; sqlite3_prepare(db, "SELECT * from test where 
id = ?", -1, , nullptr); sqlite3_bind_int(workingStatement, 0, 
0); sqlite3_step(workingStatement); sqlite3_clear_bindings(workingStatement); 
sqlite3_reset(workingStatement); sqlite3_finalize(workingStatement); // 
Crashing example. The Statement can't be created because of the
nonexisting table. sqlite3_stmt* nonWorkingStatement; sqlite3_prepare(db, 
"SELECT * from nonexisting where id = ?", -1, , nullptr); 
sqlite3_bind_int(nonWorkingStatement, 0, 0); sqlite3_step(nonWorkingStatement); 
sqlite3_clear_bindings(nonWorkingStatement); // SEGFAULT 
sqlite3_reset(nonWorkingStatement); sqlite3_finalize(nonWorkingStatement); }

Thanks for your great work!

Best regards
Christof Arnosti

-- 
Securiton AG, Alarm- und Sicherheitssysteme
Christof Arnosti
Grammetstrasse 14, 4410 Liestal

Tel. +41 58 910 55 35
christof.arno...@securiton.ch ,
www.securiton.ch 

*Unsere neue Telefonnummer:
Telefon +41 58 910 55 30, Direkt +41 58 910 55 35*
-
This e-mail is confidential and may contain privileged information. It is 
intended only for the addressees. If you have received this e-mail in error, 
kindly notify us immediately by telephone or e-mail and delete the message from 
your system. 
-
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users