[sqlite] Segmentation fault can result from setting error message parameter to NULL when calling sqlite3session_diff

2019-05-20 Thread Micah Moore
Hello,

We have found a minor bug in the session extension. The problem can occur
in sqlite3session_diff, when there is a table schema mismatch, if no error
pointer is provided.

According to the documentation of sqlite3session_diff:

> ** If the operation successful, SQLITE_OK is returned. Otherwise, an
SQLite
> ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
> ** may be set to point to a buffer containing an English language error
> ** message...

If an application calls sqlite3session_diff and encounters a schema
mismatch error, while having provided NULL for the pzErrMsg parameter, a
segmentation fault occurs.

We believe this is caused here, in sqlite3session.c: L#1627

  if( bMismatch ){
*pzErrMsg = sqlite3_mprintf("table schemas do not match");
rc = SQLITE_SCHEMA;
  }

There is no check that pzErrMsg is not NULL here prior to assignment.

There's an easy work-around: providing a pzErrMsg out parameter when
calling sqlite3session_diff resolves the crash.

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


Re: [sqlite] Segmentation fault running a query

2019-03-06 Thread Richard Hipp
This is another example of the problem described by ticket
https://www.sqlite.org/src/info/df46dfb631f75694 which is fixed in
version 3.27.2.

On 3/5/19, Peter Hardman  wrote:
> If i run the following query from Python 3.7 using the sqlite3 DBAPI
> adapter or from sqlitebrowser I get a segmentation fault.
>
> The query runs error free on PostgreSQL 9.6
>
> The query fails if the 'in' list has more than two entries.
>
> Any ideas?

-- 
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] Segmentation fault running a query

2019-03-06 Thread Richard Hipp
On 3/6/19, Peter Hardman  wrote:
>
> I've attached the database file (300K).
>

Attachments are stripped by the mailing list.  Please send via private
email directly to me.
-- 
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] Segmentation fault running a query

2019-03-06 Thread Peter Hardman
OK. I've anonymised the database and cut it down so that only the records 
extracted by the query are present. I have this feeling I've done something 
stupid with the data - but all the other queries I run against this database 
work fine.


It still gives a segfault when I run the query.

The SQLite3 version is SQLite 3.27.1 2019-02-08 13:17:39, built with zlib 
version 1.2.11 and gcc-8.2.1 20181127.


I've attached the database file (300K).



Dan Kennedy wrote on 06/03/2019 12:07:


On 6/3/62 16:37, Peter Hardman wrote:

So, I forgot I had emails from the list turned off

Integrity check shows no results.

The query fails from the CLI

The schema (of a very much cut down database) is attached.



Can you post the results of running the ".fullschema" command in the shell tool?

Thanks,

Dan.







And if it does still crash, please provide the database schema to help with 
debugging.



-Original Message-
From: sqlite-users [mailto:sqlite-users-bounces at mailinglists.sqlite.org] On 
Behalf Of Simon Slavin

Sent: Tuesday, March 05, 2019 3:14 PM
To: SQLite mailing list
Subject: Re: [sqlite] Segmentation fault running a query

On 5 Mar 2019, at 8:06pm, Peter Hardman  
wrote:

> If i run the following query from Python 3.7 using the sqlite3 DBAPI adapter 
or from sqlitebrowser I get a segmentation fault.


Please find the SQLite command-line tool on your computer.  If you don't 
already have one you can download one for your platform in the section 
"Precompiled Binaries" on


<https://sqlite.org/download.html>

Using that program, please run

PRAGMA integrity_check;

If that reports no problems (should return no results) then please run your 
SELECT query in that program just to verify that it gets the same result your 
own code does.


___
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


--

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


Re: [sqlite] Segmentation fault running a query

2019-03-06 Thread Dan Kennedy


On 6/3/62 16:37, Peter Hardman wrote:

So, I forgot I had emails from the list turned off

Integrity check shows no results.

The query fails from the CLI

The schema (of a very much cut down database) is attached.



Can you post the results of running the ".fullschema" command in the 
shell tool?


Thanks,

Dan.







And if it does still crash, please provide the database schema to help 
with debugging.



-Original Message-
From: sqlite-users [mailto:sqlite-users-bounces at 
mailinglists.sqlite.org] On Behalf Of Simon Slavin

Sent: Tuesday, March 05, 2019 3:14 PM
To: SQLite mailing list
Subject: Re: [sqlite] Segmentation fault running a query

On 5 Mar 2019, at 8:06pm, Peter Hardman somborneshetlands.co.uk> wrote:


> If i run the following query from Python 3.7 using the sqlite3 DBAPI 
adapter or from sqlitebrowser I get a segmentation fault.


Please find the SQLite command-line tool on your computer.  If you 
don't already have one you can download one for your platform in the 
section "Precompiled Binaries" on


<https://sqlite.org/download.html>

Using that program, please run

PRAGMA integrity_check;

If that reports no problems (should return no results) then please run 
your SELECT query in that program just to verify that it gets the same 
result your own code does.


___
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] Segmentation fault running a query

2019-03-06 Thread Keith Medcalf
e, p.surname,
   ...> m.address_1, m.address_2, m.address_3, m.post_town, m.county,
   ...> m.post_code, m.country, s.class_name, m.joined, s.renewed,
   ...> s.expires, s.pmt_method, m.non_renewal, m.share_info,
   ...> m.last_changed, p.person_id, r.region
   ...> from person p join mem_pers mp on p.person_id = mp.person_id
   ...> join member m on mp.member_no = m.member_no
   ...> join current_member_status s on m.member_no = s.member_no
   ...> left join in_region r on m.county = r.county
   ...>   join mem_dates d on s.expires > d.renewal_date where m.non_renewal = 
''
   ...> and p.person_id in
   ...> 
(200,270,271,355,427,484,512,598,685,724,847,922,973,1095,1189,1371,1421,1483,1516,1523,1592,1799,1866,2024,2076,2077)
   ...> ;
QUERY PLAN
|--SEARCH TABLE mem_pers AS mp USING INTEGER PRIMARY KEY (rowid=?) (~26 rows)
|--SEARCH TABLE person AS p USING INTEGER PRIMARY KEY (rowid=?) (~1 row)
|--SEARCH TABLE member AS m USING INDEX sqlite_autoindex_member_1 (member_no=?) 
(~1 row)
|--SEARCH TABLE mem_pmts AS latest USING INDEX mem_pmts_mem_no_index 
(member_no=?) (~8 rows)
|--CORRELATED SCALAR SUBQUERY 1
|  `--SEARCH TABLE mem_pmts AS even_later USING INDEX mem_pmts_mem_no_index 
(member_no=?) (~9 rows)
|--SEARCH TABLE in_region AS r USING AUTOMATIC COVERING INDEX (county=?) (~20 
rows)
`--SEARCH TABLE mem_dates AS d USING COVERING INDEX 
sqlite_autoindex_mem_dates_1 (renewal_date .exit

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-Original Message-
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Richard Hipp
>Sent: Wednesday, 6 March, 2019 04:31
>To: SQLite mailing list
>Subject: Re: [sqlite] Segmentation fault running a query
>
>On 3/6/19, Peter Hardman  wrote:
>>
>> The schema (of a very much cut down database) is attached.
>
>I translated the attached schema into SQL and appended the query.  I
>uploaded the result to https://sqlite.org/tmp/peter-hardman-001.txt
>
>I have run the resulting script through every version of SQLite I
>have
>at hand, and none of them given any trouble.  I also ran them under
>Valgrind.  No problems detected.
>
>Can anybody else reproduce the problem?
>
>--
>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

CREATE TABLE version (
major_version INTEGER NOT NULL PRIMARY KEY,
minor_version INTEGER NOT NULL,
paradox_upload TEXT,
converted TIMESTAMP NOT NULL,
created TIMESTAMP NOT NULL
);
CREATE TABLE mem_class (
class_name VARCHAR(16) NOT NULL PRIMARY KEY,
description VARCHAR(32) NOT NULL UNIQUE,
base_subscription INTEGER NOT NULL,
discount INTEGER NOT NULL,
renewal_period INTEGER NOT NULL,
joining_fee INTEGER NOT NULL,
votes INTEGER NOT NULL,
renewal_notice INTEGER NOT NULL CHECK(renewal_notice in (0, 1)),
is_active INTEGER NOT NULL CHECK(is_active in (0, 1)),
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE mem_dates (
renewal_date DATE NOT NULL PRIMARY KEY,
discount_end_date DATE NOT NULL,
membership_ceases DATE NOT NULL,
joiner_rollfwd_date DATE NOT NULL,
last_renewal_date DATE NOT NULL,
next_renewal_date DATE NOT NULL,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE pmt_method (
pmt_method VARCHAR(16) NOT NULL PRIMARY KEY,
method_code VARCHAR(8) NOT NULL UNIQUE,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE mem_source (
source VARCHAR(32) NOT NULL PRIMARY KEY,
source_code VARCHAR(8) NOT NULL UNIQUE,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE nonren_reason (
reason VARCHAR(64) NOT NULL PRIMARY KEY,
reason_code VARCHAR(8) NOT NULL UNIQUE,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE phone_type (
phone_type VARCHAR(16) NOT NULL PRIMARY KEY,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE role_type (
role_type VARCHAR(32) NOT NULL PRIMARY KEY,
role_code VARCHAR(1) NOT NULL,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE county (
county VARCHAR(32) NOT NULL PRIMARY KEY,
county_code VARCHAR(2) NOT NULL UNIQUE,
change_reason VARCHAR(32) NOT NULL,
last_changed TIMESTAMP NOT NULL
);
CREATE TABLE adj_county (
rec_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
county VARCHAR(32) NOT NULL REFERENCES county (county) ON UPDATE RESTRICT 
ON DELETE RESTRICT,
adj_county VARCHAR(32) NOT NULL REFERENCES county (county) ON UP

Re: [sqlite] Segmentation fault running a query

2019-03-06 Thread Richard Hipp
On 3/6/19, Peter Hardman  wrote:
>
> The schema (of a very much cut down database) is attached.

I translated the attached schema into SQL and appended the query.  I
uploaded the result to https://sqlite.org/tmp/peter-hardman-001.txt

I have run the resulting script through every version of SQLite I have
at hand, and none of them given any trouble.  I also ran them under
Valgrind.  No problems detected.

Can anybody else reproduce the problem?

-- 
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] Segmentation fault running a query

2019-03-06 Thread Peter Hardman

So, I forgot I had emails from the list turned off

Integrity check shows no results.

The query fails from the CLI

The schema (of a very much cut down database) is attached.



And if it does still crash, please provide the database schema to help with 
debugging.



-Original Message-
From: sqlite-users [mailto:sqlite-users-bounces at mailinglists.sqlite.org] On 
Behalf Of Simon Slavin

Sent: Tuesday, March 05, 2019 3:14 PM
To: SQLite mailing list
Subject: Re: [sqlite] Segmentation fault running a query

On 5 Mar 2019, at 8:06pm, Peter Hardman  
wrote:

> If i run the following query from Python 3.7 using the sqlite3 DBAPI adapter 
or from sqlitebrowser I get a segmentation fault.


Please find the SQLite command-line tool on your computer.  If you don't already 
have one you can download one for your platform in the section "Precompiled 
Binaries" on


<https://sqlite.org/download.html>

Using that program, please run

PRAGMA integrity_check;

If that reports no problems (should return no results) then please run your 
SELECT query in that program just to verify that it gets the same result your 
own code does.

--

Peter Hardman
('CREATE TABLE version (\nmajor_version INTEGER NOT NULL PRIMARY 
KEY,\nminor_version INTEGER NOT NULL,\nparadox_upload TEXT,\nconverted 
TIMESTAMP NOT NULL,\ncreated TIMESTAMP NOT NULL)',)
('CREATE TABLE mem_class (\nclass_name VARCHAR(16) NOT NULL PRIMARY 
KEY,\ndescription VARCHAR(32) NOT NULL UNIQUE,\nbase_subscription INTEGER NOT 
NULL,\ndiscount INTEGER NOT NULL,\nrenewal_period INTEGER NOT 
NULL,\njoining_fee INTEGER NOT NULL,\nvotes INTEGER NOT NULL,\nrenewal_notice 
INTEGER NOT NULL CHECK(renewal_notice in (0, 1)),\nis_active INTEGER NOT NULL 
CHECK(is_active in (0, 1)),\nchange_reason VARCHAR(32) NOT NULL,\nlast_changed 
TIMESTAMP NOT NULL)',)
('CREATE TABLE mem_dates (\nrenewal_date DATE NOT NULL PRIMARY 
KEY,\ndiscount_end_date DATE NOT NULL,\nmembership_ceases DATE NOT 
NULL,\njoiner_rollfwd_date DATE NOT NULL,\nlast_renewal_date DATE NOT 
NULL,\nnext_renewal_date DATE NOT NULL,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE pmt_method (\npmt_method VARCHAR(16) NOT NULL PRIMARY 
KEY,\nmethod_code VARCHAR(8) NOT NULL UNIQUE,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE mem_source (\nsource VARCHAR(32) NOT NULL PRIMARY 
KEY,\nsource_code VARCHAR(8) NOT NULL UNIQUE,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE nonren_reason (\nreason VARCHAR(64) NOT NULL PRIMARY 
KEY,\nreason_code VARCHAR(8) NOT NULL UNIQUE,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE phone_type (\nphone_type VARCHAR(16) NOT NULL PRIMARY 
KEY,\nchange_reason VARCHAR(32) NOT NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE role_type (\nrole_type VARCHAR(32) NOT NULL PRIMARY 
KEY,\nrole_code VARCHAR(1) NOT NULL,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CREATE TABLE county (\ncounty VARCHAR(32) NOT NULL PRIMARY KEY,\ncounty_code 
VARCHAR(2) NOT NULL UNIQUE,\nchange_reason VARCHAR(32) NOT NULL,\nlast_changed 
TIMESTAMP NOT NULL)',)
('CREATE TABLE adj_county (\nrec_id INTEGER NOT NULL PRIMARY KEY 
AUTOINCREMENT,\ncounty VARCHAR(32) NOT NULL REFERENCES county (county) ON 
UPDATE RESTRICT ON DELETE RESTRICT,\nadj_county VARCHAR(32) NOT NULL REFERENCES 
county (county) ON UPDATE RESTRICT ON DELETE RESTRICT,\nchange_reason 
VARCHAR(32) NOT NULL,\nlast_changed TIMESTAMP NOT NULL,\nCONSTRAINT 
adj_county_key UNIQUE (county, adj_county))',)
('CREATE TABLE sqlite_sequence(name,seq)',)
("CREATE TABLE country (\ncountry VARCHAR(32) NOT NULL PRIMARY 
KEY,\ncountry_code VARCHAR(2) NOT NULL UNIQUE,\ncalling_code VARCHAR(4) NOT 
NULL CHECK(calling_code REGEXP '^[0-9 ]*$'),\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)",)
('CREATE TABLE region (\nregion VARCHAR(32) NOT NULL PRIMARY KEY,\nregion_code 
VARCHAR(2) NOT NULL UNIQUE,\nchange_reason VARCHAR(32) NOT NULL,\nlast_changed 
TIMESTAMP NOT NULL)',)
('CREATE TABLE in_region (\nrec_id INTEGER NOT NULL PRIMARY KEY 
AUTOINCREMENT,\nregion VARCHAR(32) NOT NULL REFERENCES region (region) ON 
UPDATE RESTRICT ON DELETE RESTRICT,\ncounty VARCHAR(32) NOT NULL REFERENCES 
county (county) ON UPDATE RESTRICT ON DELETE RESTRICT,\ncountry VARCHAR(32) NOT 
NULL REFERENCES country (country) ON UPDATE RESTRICT ON DELETE 
RESTRICT,\nchange_reason VARCHAR(32) NOT NULL,\nlast_changed TIMESTAMP NOT 
NULL,\nCONSTRAINT in_region_key UNIQUE (region, county, country))',)
('CREATE TABLE post_area (\noutward_code VARCHAR(4) NOT NULL PRIMARY 
KEY,\narea_name VARCHAR(32) NOT NULL UNIQUE,\nlatitude FLOAT NOT 
NULL,\nlongitude FLOAT NOT NULL,\neasting INTEGER NOT NULL,\nnorthing INTEGER 
NOT NULL,\ngrid_ref CHARACTER(8) NOT NULL,\nchange_reason VARCHAR(32) NOT 
NULL,\nlast_changed TIMESTAMP NOT NULL)',)
('CRE

Re: [sqlite] Segmentation fault running a query

2019-03-05 Thread David Raymond
And if it does still crash, please provide the database schema to help with 
debugging.


-Original Message-
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Simon Slavin
Sent: Tuesday, March 05, 2019 3:14 PM
To: SQLite mailing list
Subject: Re: [sqlite] Segmentation fault running a query

On 5 Mar 2019, at 8:06pm, Peter Hardman  wrote:

> If i run the following query from Python 3.7 using the sqlite3 DBAPI adapter 
> or from sqlitebrowser I get a segmentation fault.

Please find the SQLite command-line tool on your computer.  If you don't 
already have one you can download one for your platform in the section 
"Precompiled Binaries" on

<https://sqlite.org/download.html>

Using that program, please run

PRAGMA integrity_check;

If that reports no problems (should return no results) then please run your 
SELECT query in that program just to verify that it gets the same result your 
own code does.
___
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] Segmentation fault running a query

2019-03-05 Thread Simon Slavin
On 5 Mar 2019, at 8:06pm, Peter Hardman  wrote:

> If i run the following query from Python 3.7 using the sqlite3 DBAPI adapter 
> or from sqlitebrowser I get a segmentation fault.

Please find the SQLite command-line tool on your computer.  If you don't 
already have one you can download one for your platform in the section 
"Precompiled Binaries" on



Using that program, please run

PRAGMA integrity_check;

If that reports no problems (should return no results) then please run your 
SELECT query in that program just to verify that it gets the same result your 
own code does.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Segmentation fault running a query

2019-03-05 Thread Peter Hardman
If i run the following query from Python 3.7 using the sqlite3 DBAPI 
adapter or from sqlitebrowser I get a segmentation fault.


The query runs error free on PostgreSQL 9.6

The query fails if the 'in' list has more than two entries.

Any ideas? I could create a test database but it will take a while as it 
has personal information in which I would have to obfuscate to avoid 
falling foul of the GDPR.


Query:

select  m.member_no, p.title, p.initials, p.forename, p.surname,
m.address_1, m.address_2, m.address_3, m.post_town, m.county,
m.post_code, m.country, s.class_name, m.joined, s.renewed,
s.expires, s.pmt_method, m.non_renewal, m.share_info,
m.last_changed, p.person_id, r.region
from person p join mem_pers mp on p.person_id = mp.person_id
join member m on mp.member_no = m.member_no
join current_member_status s on m.member_no = s.member_no
left join in_region r on m.county = r.county
 join mem_dates d on s.expires > d.renewal_date where m.non_renewal = ''
and p.person_id in 
(200,270,271,355,427,484,512,598,685,724,847,922,973,1095,1189,1371,1421,1483,1516,1523,1592,1799,1866,2024,2076,2077) 


 order by m.country, m.county, p.surname, p.initials

Core dump (the interesting bit only):

[peter@system04 ppd-memrpt2]$ coredumpctl info 10267
   PID: 10267 (sqlitebrowser)
   UID: 1000 (peter)
   GID: 1000 (peter)
Signal: 11 (SEGV)
 Timestamp: Tue 2019-03-05 18:55:38 GMT (55min ago)
  Command Line: sqlitebrowser
Executable: /usr/bin/sqlitebrowser
 Control Group: /user.slice/user-1000.slice/session-1.scope
  Unit: session-1.scope
 Slice: user-1000.slice
   Session: 1
 Owner UID: 1000 (peter)
   Boot ID: f27026461d4944c8a24ca6524def7c0c
Machine ID: 47f95fceb9d84436be17de2a1639655e
  Hostname: system04
   Storage: 
/var/lib/systemd/coredump/core.sqlitebrowser.1000.f27026461d4944c8a24ca6524def7c0c.10267.1551812138>

   Message: Process 10267 (sqlitebrowser) of user 1000 dumped core.

Stack trace of thread 10267:
#0  0x7ffaf1357223 sqlite3VdbeFindCompare 
(libsqlite3.so.0)
#1  0x7ffaf12ba157 sqlite3BtreeMovetoUnpacked 
(libsqlite3.so.0)

#2  0x7ffaf134db86 sqlite3VdbeExec (libsqlite3.so.0)
#3  0x7ffaf1352920 sqlite3_step (libsqlite3.so.0)
#4  0x556bb8b1b09e _ZN10MainWindow12executeQueryEv 
(sqlitebrowser)

#5  0x556bb8c1da2f n/a (sqlitebrowser)
#6  0x7ffaf0a4187c 
_ZN11QMetaObject8activateEP7QObjectiiPPv (libQt5Core.so.5)
#7  0x7ffaf16f5633 _ZN7QAction9triggeredEb 
(libQt5Widgets.so.5)
#8  0x7ffaf16f7d1a 
_ZN7QAction8activateENS_11ActionEventE (libQt5Widgets.so.5)

#9  0x7ffaf17ea45e n/a (libQt5Widgets.so.5)
#10 0x7ffaf17ea696 
_ZN15QAbstractButton17mouseReleaseEventEP11QMouseEvent (libQt5Widgets.so.5)
#11 0x7ffaf18da04b 
_ZN11QToolButton17mouseReleaseEventEP11QMouseEvent (libQt5Widgets.so.5)
#12 0x7ffaf173cb68 _ZN7QWidget5eventEP6QEvent 
(libQt5Widgets.so.5)
#13 0x7ffaf18da0f4 _ZN11QToolButton5eventEP6QEvent 
(libQt5Widgets.so.5)
#14 0x7ffaf16fbe24 
_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent 
(libQt5Widgets.so.5)
#15 0x7ffaf1703929 
_ZN12QApplication6notifyEP7QObjectP6QEvent (libQt5Widgets.so.5)
#16 0x7ffaf0a16e99 
_ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent (libQt5Core.so.5)
#17 0x7ffaf1702c08 
_ZN19QApplicationPrivate14sendMouseEventEP7QWidgetP11QMouseEventS1_S1_PS1_R8QPoi>

lines


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


Re: [sqlite] Segmentation fault when using window function with (nested?) subquery

2018-12-06 Thread Richard Hipp
On 12/6/18, Larry Brasfield  wrote:
>
> The above fault and non-fault also occur on Windows 10 x64 (with a 64-bit
> build) with the SQLite3 v3.26 shell.  I can provide build options and
> compile flags if that would be useful.

Thanks, but I have no trouble reproducing the problem.  It is an issue
with the byte-code generator for window functions.  If you run with
assert()s enabled, it hits an assert() early on. This problem has
existed ever since window functions were added in version 3.25.0.  It
is not something new to 3.26.0.

-- 
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] Segmentation fault when using window function with (nested?) subquery

2018-12-06 Thread Larry Brasfield
Gene Sacky wrote:
> This query causes segmentation fault in SQLite 3.26.0 (on macOS 10.14.1).
> --
> SELECT * FROM(
> SELECT * FROM (SELECT 1 AS c) WHERE c IN (
> SELECT (row_number() OVER()) FROM (VALUES (0))
> )
> )
> --
> 
> However, no error occurs in the following queries. The only difference is
> whether it is wrapped with "SELECT * FROM" .
> --
> SELECT * FROM(
> SELECT 1 AS c WHERE c IN (
> SELECT (row_number() OVER()) FROM (VALUES (0))
> )
> )
> --
> 
> --
> SELECT * FROM (SELECT 1 AS c) WHERE c IN (
> SELECT (row_number() OVER()) FROM (VALUES (0))
> )
> --

The above fault and non-fault also occur on Windows 10 x64 (with a 64-bit 
build) with the SQLite3 v3.26 shell.  I can provide build options and compile 
flags if that would be useful.

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


[sqlite] Segmentation fault when using window function with (nested?) subquery

2018-12-06 Thread Gene Sacky
This query causes segmentation fault in SQLite 3.26.0 (on macOS 10.14.1).
--
SELECT * FROM(
SELECT * FROM (SELECT 1 AS c) WHERE c IN (
SELECT (row_number() OVER()) FROM (VALUES (0))
)
)
--

However, no error occurs in the following queries. The only difference is
whether it is wrapped with "SELECT * FROM" .
--
SELECT * FROM(
SELECT 1 AS c WHERE c IN (
SELECT (row_number() OVER()) FROM (VALUES (0))
)
)
--

--
SELECT * FROM (SELECT 1 AS c) WHERE c IN (
SELECT (row_number() OVER()) FROM (VALUES (0))
)
--


I found similar bug report about window function but I think it is unrelated
because it was fixed before 3.26.0.
http://sqlite.1065341.n5.nabble.com/Segmentation-Fault-When-Using-Window-Function-td104584.html






--
Sent from: http://sqlite.1065341.n5.nabble.com/
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-09 Thread Jeremy Evans
On 11/09 09:26, Richard Hipp wrote:
> On 11/7/18, Jeremy Evans  wrote:
> > The following SQL causes a segmentation fault on:
> 
> Thank you for the bug report and reproducible test case.
> 
> The problem actually had nothing to do with window functions.  The use
> of window functions merely made the bug easier to hit.  The bug has
> gone undetected in the code for over three years.  It is now fixed on
> trunk.  If you can, please download and compile the latest trunk
> version and let us know whether or not it is working better for you.
> 
> If you do not want to download and compile from canonical sources, you can 
> patch
> your "sqlite3.c" source file by removing a single line of code:

I have tested this patch and confirmed that it fixes the issue.  Thank
you very much.

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


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-09 Thread Simon Slavin
On 9 Nov 2018, at 3:35pm, Dennis Clarke  wrote:

> The list mail server sends this out about thirty times.

I saw just one copy, so I think the problem is nearer your end of the route.

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


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-09 Thread Richard Hipp
On 11/9/18, Dennis Clarke  wrote:
> The list mail server sends this out about thirty times.  Not sure if
> anyone else sees abusive duplicates from the sqlite mail list server
> but I certainly do.

If you will send me headers to a few of this message by private email,
I will try to debug it.
-- 
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] Segmentation Fault When Using Window Function

2018-11-09 Thread Stephen Chrzanowski
I'm only seeing the one email, no duplicates.

On Fri, Nov 9, 2018 at 10:35 AM Dennis Clarke  wrote:

> On 11/08/2018 04:05 PM, Richard Hipp wrote:
> > In case you are not following the ticket at...
>
> 
>
> The list mail server sends this out about thirty times.  Not sure if
> anyone else sees abusive duplicates from the sqlite mail list server
> but I certainly do.
>
> Dennis
>
> ___
> 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] Segmentation Fault When Using Window Function

2018-11-09 Thread David Raymond
Commented out that 1 line from the amalgamation and can confirm that I'm no 
longer crashing on those queries.


-Original Message-
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Richard Hipp
Sent: Friday, November 09, 2018 9:26 AM
To: SQLite mailing list
Cc: c...@jeremyevans.net
Subject: Re: [sqlite] Segmentation Fault When Using Window Function

On 11/7/18, Jeremy Evans  wrote:
> The following SQL causes a segmentation fault on:

Thank you for the bug report and reproducible test case.

The problem actually had nothing to do with window functions.  The use
of window functions merely made the bug easier to hit.  The bug has
gone undetected in the code for over three years.  It is now fixed on
trunk.  If you can, please download and compile the latest trunk
version and let us know whether or not it is working better for you.

If you do not want to download and compile from canonical sources, you can patch
your "sqlite3.c" source file by removing a single line of code:

--- sqlite3.c-baseline
+++ sqlite3.c
@@ -139937,21 +139937,20 @@
   );
   sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
   sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
   if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
   if( pTabItem->fg.viaCoroutine ){
 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
 testcase( pParse->db->mallocFailed );
 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
   pTabItem->regResult, 1);
 sqlite3VdbeGoto(v, addrTop);
-pTabItem->fg.viaCoroutine = 0;  /* REMOVE THIS LINE OF CODE */
   }else{
 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
   }
   sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
   sqlite3VdbeJumpHere(v, addrTop);
   sqlite3ReleaseTempReg(pParse, regRecord);

   /* Jump here when skipping the initialization */
   sqlite3VdbeJumpHere(v, addrInit);
-- 
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-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-09 Thread Dennis Clarke

On 11/08/2018 04:05 PM, Richard Hipp wrote:

In case you are not following the ticket at...




The list mail server sends this out about thirty times.  Not sure if 
anyone else sees abusive duplicates from the sqlite mail list server

but I certainly do.

Dennis

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


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-09 Thread Richard Hipp
On 11/7/18, Jeremy Evans  wrote:
> The following SQL causes a segmentation fault on:

Thank you for the bug report and reproducible test case.

The problem actually had nothing to do with window functions.  The use
of window functions merely made the bug easier to hit.  The bug has
gone undetected in the code for over three years.  It is now fixed on
trunk.  If you can, please download and compile the latest trunk
version and let us know whether or not it is working better for you.

If you do not want to download and compile from canonical sources, you can patch
your "sqlite3.c" source file by removing a single line of code:

--- sqlite3.c-baseline
+++ sqlite3.c
@@ -139937,21 +139937,20 @@
   );
   sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
   sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
   if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
   if( pTabItem->fg.viaCoroutine ){
 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
 testcase( pParse->db->mallocFailed );
 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
   pTabItem->regResult, 1);
 sqlite3VdbeGoto(v, addrTop);
-pTabItem->fg.viaCoroutine = 0;  /* REMOVE THIS LINE OF CODE */
   }else{
 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
   }
   sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
   sqlite3VdbeJumpHere(v, addrTop);
   sqlite3ReleaseTempReg(pParse, regRecord);

   /* Jump here when skipping the initialization */
   sqlite3VdbeJumpHere(v, addrInit);
-- 
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] Segmentation Fault When Using Window Function

2018-11-08 Thread Richard Hipp
On 11/8/18, J. King  wrote:
> On 2018-11-08 16:05:11, "Richard Hipp"  wrote:
>
>>In case you are not following the ticket at
>>https://www.sqlite.org/src/tktview/787fa716be3a7f650cac1b1413f12f95f5e7639d,
>>we have simplified the test case to the following:
>>
>
> Richard,
> My mail client appears to have exposed a bug in Fossil. In including the
> comma in its link-making of the URL (i.e.
> ),
> it brought me to a technically valid (response status 200) resource with
> an empty ticket metadata table save for a ticket UUID of "Deleted". As
> the ticket UUID is not deleted (it is invalid) I would have expected a
> 404 response with an appropriate message.

Thank you.  The obvious work-around here is to omit the common on the
end of the URL.  I'm going to continue focusing on the crash bug right
this moment

-- 
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] Segmentation Fault When Using Window Function

2018-11-08 Thread J. King

On 2018-11-08 16:05:11, "Richard Hipp"  wrote:


In case you are not following the ticket at
https://www.sqlite.org/src/tktview/787fa716be3a7f650cac1b1413f12f95f5e7639d,
we have simplified the test case to the following:



Richard,
My mail client appears to have exposed a bug in Fossil. In including the 
comma in its link-making of the URL (i.e. 
), 
it brought me to a technically valid (response status 200) resource with 
an empty ticket metadata table save for a ticket UUID of "Deleted". As 
the ticket UUID is not deleted (it is invalid) I would have expected a 
404 response with an appropriate message.


--
J. King

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


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-08 Thread Richard Hipp
In case you are not following the ticket at
https://www.sqlite.org/src/tktview/787fa716be3a7f650cac1b1413f12f95f5e7639d,
we have simplified the test case to the following:

CREATE TABLE t5(a, b, c, d);
CREATE INDEX t5a ON t5(a);
CREATE INDEX t5b ON t5(b);
CREATE TABLE t6(e);
INSERT INTO t6 VALUES(1);
INSERT INTO t5 VALUES(1,1,1,1), (2,2,2,2);
SELECT * FROM t5 WHERE (a=1 OR b=2) AND c IN (
  SELECT e FROM (SELECT DISTINCT e FROM t6) WHERE e=1
);

The above fails going back to SQLite version 3.8.11 (2015-07-27).

On 11/7/18, Jeremy Evans  wrote:
> The following SQL causes a segmentation fault on:
>
> * OpenBSD -current (3.25.1 and 3.25.3)
> * MacOS 10.14 (3.25.2)
>
> No segmentation fault using the precompiled Windows binary, though.
>
> CREATE TABLE `artists` (
>   `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
>   `name` varchar(255)
> );
> CREATE TABLE `albums` (
>   `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
>   `name` varchar(255),
>   `artist_id` integer REFERENCES `artists`
> );
> INSERT INTO `artists` (`name`) VALUES ('Ar');
> INSERT INTO `albums` (`name`, `artist_id`) VALUES ('Al', 1);
> SELECT `artists`.*
> FROM `artists`
> INNER JOIN `artists` AS 'b' ON (`b`.`id` = `artists`.`id`)
> WHERE (`artists`.`id` IN (
>   SELECT `albums`.`artist_id`
>   FROM `albums`
>   WHERE ((`name` = 'Al')
> AND (`albums`.`artist_id` IS NOT NULL)
> AND (`albums`.`id` IN (
>   SELECT `id`
>   FROM (
> SELECT `albums`.`id`,
>row_number() OVER (
>  PARTITION BY `albums`.`artist_id`
>  ORDER BY `name`
>) AS 'x'
> FROM `albums`
> WHERE (`name` = 'Al')
>   ) AS 't1'
>   WHERE (`x` = 1)
> ))
> AND (`albums`.`id` IN (1, 2)))
> ));
>
> gdb output from OpenBSD-current:
>
> (gdb) bt
> #0  0x16ae6e4a888d in sqlite3VdbeExec (p=0x16ae5cb282c8) at
> sqlite3.c:87803
> #1  0x16ae6e46dd33 in sqlite3Step (p=0x16ae5cb282c8) at sqlite3.c:81043
> #2  0x16ae6e46d95a in sqlite3_step (pStmt=0x16ae5cb282c8) at
> sqlite3.c:81106
> #3  0x16abb6a3a6e6 in ?? () from /usr/local/bin/sqlite3
> #4  0x16abb6a20e6d in ?? () from /usr/local/bin/sqlite3
> #5  0x16abb6a3d0da in ?? () from /usr/local/bin/sqlite3
> #6  0x16abb6a21b6a in ?? () from /usr/local/bin/sqlite3
> #7  0x16abb6a17717 in ?? () from /usr/local/bin/sqlite3
> #8  0x16abb6a10056 in ?? () from /usr/local/bin/sqlite3
> #9  0x in ?? ()
> (gdb) info locals
> pC = (VdbeCursor *) 0x0
> pCrsr = (BtCursor *) 0x16ae5cb29ac8
> res = 1
> azType = 0x16ae6e5a8c00
> aLTb = 0x16ae6e422130 "\001"
> aEQb = 0x16ae6e422136 ""
> aGTb = 0x16ae6e42213c "\001"
> and_logic = 0x16ae6e422142 ""
> or_logic = 0x16ae6e42214b ""
> aFlag = 0x16ae6e422154
> aZero = 0x16ae6e5ac3e0 ""
> vfsFlags = 1054
> aOp = (Op *) 0x16ae54417008
> pOp = (Op *) 0x16ae54417ff8
> rc = 0
> db = (sqlite3 *) 0x16ae921ec408
> resetSchemaOnFault = 0 '\0'
> encoding = 1 '\001'
> iCompare = 1
> nVmStep = 291
> nProgressLimit = 4294967295
> aMem = (Mem *) 0x16ae544184b0
> pIn1 = (Mem *) 0x16ae54418600
> pIn2 = (Mem *) 0x16ae544187f8
> pIn3 = (Mem *) 0x16ae54418590
> pOut = (Mem *) 0x16ae54418a60
>
> If other gdb information would be helpful, please let me know.
>
> Thanks,
> Jeremy
> ___
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
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] Segmentation Fault When Using Window Function

2018-11-08 Thread Olivier Mascia
Hello,

Without me knowing if it is related to your problem, I wonder what's the intent 
here?

> SELECT `artists`.*
> FROM `artists`
> INNER JOIN `artists` AS 'b' ON (`b`.`id` = `artists`.`id`)

-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia


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


Re: [sqlite] Segmentation Fault When Using Window Function

2018-11-08 Thread David Raymond
This crashes both my self-compiled version of the CLI _and_ the pre-compiled 
one on Windows as well.
SQLite: 3.25.2
Windows 7


-Original Message-
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Jeremy Evans
Sent: Wednesday, November 07, 2018 7:36 PM
To: sqlite-users@mailinglists.sqlite.org
Subject: [sqlite] Segmentation Fault When Using Window Function

The following SQL causes a segmentation fault on:

* OpenBSD -current (3.25.1 and 3.25.3)
* MacOS 10.14 (3.25.2)

No segmentation fault using the precompiled Windows binary, though.

CREATE TABLE `artists` (
  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` varchar(255)
);
CREATE TABLE `albums` (
  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` varchar(255),
  `artist_id` integer REFERENCES `artists`
);
INSERT INTO `artists` (`name`) VALUES ('Ar');
INSERT INTO `albums` (`name`, `artist_id`) VALUES ('Al', 1);
SELECT `artists`.*
FROM `artists`
INNER JOIN `artists` AS 'b' ON (`b`.`id` = `artists`.`id`)
WHERE (`artists`.`id` IN (
  SELECT `albums`.`artist_id`
  FROM `albums`
  WHERE ((`name` = 'Al')
AND (`albums`.`artist_id` IS NOT NULL)
AND (`albums`.`id` IN (
  SELECT `id`
  FROM (
SELECT `albums`.`id`,
   row_number() OVER (
 PARTITION BY `albums`.`artist_id`
 ORDER BY `name`
   ) AS 'x'
FROM `albums`
WHERE (`name` = 'Al')
  ) AS 't1'
  WHERE (`x` = 1)
))
AND (`albums`.`id` IN (1, 2)))
));

gdb output from OpenBSD-current:

(gdb) bt
#0  0x16ae6e4a888d in sqlite3VdbeExec (p=0x16ae5cb282c8) at sqlite3.c:87803
#1  0x16ae6e46dd33 in sqlite3Step (p=0x16ae5cb282c8) at sqlite3.c:81043
#2  0x16ae6e46d95a in sqlite3_step (pStmt=0x16ae5cb282c8) at sqlite3.c:81106
#3  0x16abb6a3a6e6 in ?? () from /usr/local/bin/sqlite3
#4  0x16abb6a20e6d in ?? () from /usr/local/bin/sqlite3
#5  0x16abb6a3d0da in ?? () from /usr/local/bin/sqlite3
#6  0x16abb6a21b6a in ?? () from /usr/local/bin/sqlite3
#7  0x16abb6a17717 in ?? () from /usr/local/bin/sqlite3
#8  0x16abb6a10056 in ?? () from /usr/local/bin/sqlite3
#9  0x in ?? ()
(gdb) info locals
pC = (VdbeCursor *) 0x0
pCrsr = (BtCursor *) 0x16ae5cb29ac8
res = 1
azType = 0x16ae6e5a8c00
aLTb = 0x16ae6e422130 "\001"
aEQb = 0x16ae6e422136 ""
aGTb = 0x16ae6e42213c "\001"
and_logic = 0x16ae6e422142 ""
or_logic = 0x16ae6e42214b ""
aFlag = 0x16ae6e422154
aZero = 0x16ae6e5ac3e0 ""
vfsFlags = 1054
aOp = (Op *) 0x16ae54417008
pOp = (Op *) 0x16ae54417ff8
rc = 0
db = (sqlite3 *) 0x16ae921ec408
resetSchemaOnFault = 0 '\0'
encoding = 1 '\001'
iCompare = 1
nVmStep = 291
nProgressLimit = 4294967295
aMem = (Mem *) 0x16ae544184b0
pIn1 = (Mem *) 0x16ae54418600
pIn2 = (Mem *) 0x16ae544187f8
pIn3 = (Mem *) 0x16ae54418590
pOut = (Mem *) 0x16ae54418a60

If other gdb information would be helpful, please let me know.

Thanks,
Jeremy
___
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


[sqlite] Segmentation Fault When Using Window Function

2018-11-08 Thread Jeremy Evans
The following SQL causes a segmentation fault on:

* OpenBSD -current (3.25.1 and 3.25.3)
* MacOS 10.14 (3.25.2)

No segmentation fault using the precompiled Windows binary, though.

CREATE TABLE `artists` (
  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` varchar(255)
);
CREATE TABLE `albums` (
  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` varchar(255),
  `artist_id` integer REFERENCES `artists`
);
INSERT INTO `artists` (`name`) VALUES ('Ar');
INSERT INTO `albums` (`name`, `artist_id`) VALUES ('Al', 1);
SELECT `artists`.*
FROM `artists`
INNER JOIN `artists` AS 'b' ON (`b`.`id` = `artists`.`id`)
WHERE (`artists`.`id` IN (
  SELECT `albums`.`artist_id`
  FROM `albums`
  WHERE ((`name` = 'Al')
AND (`albums`.`artist_id` IS NOT NULL)
AND (`albums`.`id` IN (
  SELECT `id`
  FROM (
SELECT `albums`.`id`,
   row_number() OVER (
 PARTITION BY `albums`.`artist_id`
 ORDER BY `name`
   ) AS 'x'
FROM `albums`
WHERE (`name` = 'Al')
  ) AS 't1'
  WHERE (`x` = 1)
))
AND (`albums`.`id` IN (1, 2)))
));

gdb output from OpenBSD-current:

(gdb) bt
#0  0x16ae6e4a888d in sqlite3VdbeExec (p=0x16ae5cb282c8) at sqlite3.c:87803
#1  0x16ae6e46dd33 in sqlite3Step (p=0x16ae5cb282c8) at sqlite3.c:81043
#2  0x16ae6e46d95a in sqlite3_step (pStmt=0x16ae5cb282c8) at sqlite3.c:81106
#3  0x16abb6a3a6e6 in ?? () from /usr/local/bin/sqlite3
#4  0x16abb6a20e6d in ?? () from /usr/local/bin/sqlite3
#5  0x16abb6a3d0da in ?? () from /usr/local/bin/sqlite3
#6  0x16abb6a21b6a in ?? () from /usr/local/bin/sqlite3
#7  0x16abb6a17717 in ?? () from /usr/local/bin/sqlite3
#8  0x16abb6a10056 in ?? () from /usr/local/bin/sqlite3
#9  0x in ?? ()
(gdb) info locals
pC = (VdbeCursor *) 0x0
pCrsr = (BtCursor *) 0x16ae5cb29ac8
res = 1
azType = 0x16ae6e5a8c00
aLTb = 0x16ae6e422130 "\001"
aEQb = 0x16ae6e422136 ""
aGTb = 0x16ae6e42213c "\001"
and_logic = 0x16ae6e422142 ""
or_logic = 0x16ae6e42214b ""
aFlag = 0x16ae6e422154
aZero = 0x16ae6e5ac3e0 ""
vfsFlags = 1054
aOp = (Op *) 0x16ae54417008
pOp = (Op *) 0x16ae54417ff8
rc = 0
db = (sqlite3 *) 0x16ae921ec408
resetSchemaOnFault = 0 '\0'
encoding = 1 '\001'
iCompare = 1
nVmStep = 291
nProgressLimit = 4294967295
aMem = (Mem *) 0x16ae544184b0
pIn1 = (Mem *) 0x16ae54418600
pIn2 = (Mem *) 0x16ae544187f8
pIn3 = (Mem *) 0x16ae54418590
pOut = (Mem *) 0x16ae54418a60

If other gdb information would be helpful, please let me know.

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


Re: [sqlite] segmentation fault in sqlite api call

2018-10-22 Thread Olivier Mascia
Your query string is ~ 61 characters (did not count precisely), not including 
the key length not the value length. Are you sure the real tests you run do not 
overflow the fixed buffer char query[200] which can hold no more than 199 
characters?  You would have huge problems as soon as strlen(key) + 
strlen(query) > ~139.

Besides, there is still no point passing a char** to mydef_set().
You might as well have:
> int mydef_set(sqlite3 *db,char *key, char *value)
and call it as:
> mydef_set(db,"sssi",val);

And the code for mod_init() copied from your initial email can't be the code 
you compile along the remaining bits of the sample you provided. That function 
expect db to be a global, yet it returns it after changing it, it frees a query 
which was nowhere declared/allocated,...

I sincerely think what you are looking at are weird bugs in your code, and you 
might be loosing precious time wondering what might go wrong in SQLite code : 
anything and everything if the caller plays fool.

If you want some more help from the community, I suggest you should write a 
short self-contained sample as you tried to do, but this time check that it 
compiles fine (what you showed until now can't possibly even compile), and run 
and produces the same problem as your real program then show it.  Please also 
tell what your platform is and how is SQLite linked to your code (static lib, 
dynamic lib, or compiled in along with your project code).

-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia

> sqlite3 *mod_init() {
> 
>/* Open database */
>//rc = sqlite3_open("test.db", >db);
>lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL);
>if( lastError ) {
>fprintf(stderr, "Can't open database: %s\n",
> sqlite3_errmsg(dbObj->db));
>free(query);
>return(0);
>} else {
>fprintf(stdout, "Opened database successfully\n");
>}
>memset(query,0,200);
>strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
>"key   TEXT PRIMARY KEY   NOT NULL," \
>"valueVARCHAR(100));");
> 
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
> 
> 
>if( lastError != SQLITE_OK ){
>fprintf(stderr, "SQL error: %s\n", zErrMsg);
>sqlite3_free(zErrMsg);
>} else {
>fprintf(stdout, "Table created successfully\n");
>}
> return db;
> }
> 

> Le 22 oct. 2018 à 07:15, Ratheendran R  a écrit :
> 
> int mydef_set(sqlite3 *db,char *key, char **value)
> {
>char *zErrMsg = 0;
>int rc;
>char query[200]
>sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
> ('%s', '%s');",key,*value);
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
>if( lastError != SQLITE_OK ) {
>  fprintf(stderr, "SQL error: %s\n", zErrMsg);
>  sqlite3_free(zErrMsg);
>   } else {
>  fprintf(stdout, "Update done successfully\n");
>   }
>return lastError;
> }
> 
> 
> int main()
> {
> 
> 
>sqlite3 *db;
>db=mod_init();
>char *val=malloc(1000);
>//strcpy(val,
>char dest[]="axzchsdjzcjsdjdcfsjhgfcshgsdfgsfg h
> dbhjbbssdfsdsgffjhdsgfjg";
>strcpy(val,dest);
> 
>mydef_set(db,"sssi",);
> 
> }



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


Re: [sqlite] segmentation fault in sqlite api call

2018-10-21 Thread Ratheendran R
Thanks Olivier Mascia for the tips and suggestion I will definitely try out.

sorry for the code with the double pointer which has raised lot of
confusion I ensured this fault raised is not beacuse of any of my pointer
usage .

I am having a workaround with key/value memory allocation in heap and
double pointer seen was its residue, I am wondering why this fault occurs
for stack allocation.

int mydef_set(sqlite3 *db,char *key, char **value)
{
char *zErrMsg = 0;
int rc;
char query[200]
sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
('%s', '%s');",key,*value);
/* Execute SQL statement */
lastError = sqlite3_exec(db, query, 0, 0, );
if( lastError != SQLITE_OK ) {
  fprintf(stderr, "SQL error: %s\n", zErrMsg);
  sqlite3_free(zErrMsg);
   } else {
  fprintf(stdout, "Update done successfully\n");
   }
return lastError;
}


int main()
{


sqlite3 *db;
db=mod_init();
char *val=malloc(1000);
//strcpy(val,
char dest[]="axzchsdjzcjsdjdcfsjhgfcshgsdfgsfg h
dbhjbbssdfsdsgffjhdsgfjg";
strcpy(val,dest);

mydef_set(db,"sssi",);

}


Ratheendran





On Sun, Oct 21, 2018 at 10:46 PM Olivier Mascia  wrote:

> Hi,
>
> mydef_set probably overflows your 'query' variable of which you don't show
> declaration but I guess it is 200 bytes seeing your memset(query,0,200);
> strcpy(query, ...
>
> This above and why this char** buffer in mydef_set prototype?
> Think about what your intent was. Compare to what you did (right) for key
> parameter.
>
> Try to stop writing software that sprintf things to fixed sized buffers.
> Especially when the purpose is to dynamically build SQL statements. Learn
> about using parameters in your SQL statement, prepare once and execute
> many, supplying values for the parameters at each run (step).
>
> Hope it will help.
> --
> Best Regards, Meilleures salutations, Met vriendelijke groeten,
> Olivier Mascia
>
> > Le 21 oct. 2018 à 18:54, Ratheendran R  a
> écrit :
> >
> > Hi,
> >
> > I am a embedded engineer and new to sqlite,we want to use sqlite for our
> > local storage instead of file i/o.
> >
> > I have created a table with key and value records of char type,now if I
> try
> > store a value with string length more than 50 char I get segmentation
> > fault,please see the code below and let me know if I can improve it.
> >
> > sqlite3 *mod_init() {
> >
> >/* Open database */
> >//rc = sqlite3_open("test.db", >db);
> >lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE |
> > SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL);
> >if( lastError ) {
> >fprintf(stderr, "Can't open database: %s\n",
> > sqlite3_errmsg(dbObj->db));
> >free(query);
> >return(0);
> >} else {
> >fprintf(stdout, "Opened database successfully\n");
> >}
> >memset(query,0,200);
> >strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
> >"key   TEXT PRIMARY KEY   NOT NULL," \
> >"valueVARCHAR(100));");
> >
> >/* Execute SQL statement */
> >lastError = sqlite3_exec(db, query, 0, 0, );
> >
> >
> >if( lastError != SQLITE_OK ){
> >fprintf(stderr, "SQL error: %s\n", zErrMsg);
> >sqlite3_free(zErrMsg);
> >} else {
> >fprintf(stdout, "Table created successfully\n");
> >}
> > return db;
> > }
> >
> >
> >
> > int mydef_set(cf_db_t *dbObj,char *key, char **value)
> > {
> >char *zErrMsg = 0;
> >int rc;
> >sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
> > ('%s', '%s');",key,*value);
> >/* Execute SQL statement */
> >lastError = sqlite3_exec(db, query, 0, 0, );
> >if( lastError != SQLITE_OK ) {
> >  fprintf(stderr, "SQL error: %s\n", zErrMsg);
> >  sqlite3_free(zErrMsg);
> >   } else {
> >  fprintf(stdout, "Update done successfully\n");
> >   }
> >return lastError;
> > }
> >
> >
> > int main()
> > {
> >sqlite3 *db;
> >db=mod_init();
> >mydef_set(db,"sssi","Hitjkahzdsdhdjksdhjsdhsjfhjsdhfjhsjd bcn
> > bsdbgfhjsdgcsdfcbscbshdfgchdsfbbsdfcsfg");
> > }
> >
> > Thanks,
> > Ratheendran
> > ___
> > 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
>
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] segmentation fault in sqlite api call

2018-10-21 Thread Keith Medcalf

You have a vast number of undeclared variables that are pointing into 
super-crash-land:

sqlite3 *mod_init() 

  db is undeclared
  dbObj is undeclared
  lastError is undeclared
  query is undeclared
  zErrMsg is undeclared

int mydef_set(cf_db_t *dbObj,char *key, char **value)

  type cf_db_t is undeclared
  query is undeclared
  db is undeclared
  lastError is undeclared
  char **value does not match passed type
  
int main()

  in call to mydef_set
   parameter 1 (sqlite3*) does not match expected (cf_db_t*)
   parameter 2 (char*) does not match expected (char**)

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-Original Message-
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Ratheendran R
>Sent: Sunday, 21 October, 2018 10:55
>To: sqlite-users@mailinglists.sqlite.org
>Subject: [sqlite] segmentation fault in sqlite api call
>
>Hi,
>
>I am a embedded engineer and new to sqlite,we want to use sqlite for
>our
>local storage instead of file i/o.
>
>I have created a table with key and value records of char type,now if
>I try
>store a value with string length more than 50 char I get segmentation
>fault,please see the code below and let me know if I can improve it.
>
>sqlite3 *mod_init() {
>
>/* Open database */
>//rc = sqlite3_open("test.db", >db);
>lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE
>|
>SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX ,
>NULL);
>if( lastError ) {
>fprintf(stderr, "Can't open database: %s\n",
>sqlite3_errmsg(dbObj->db));
>free(query);
>return(0);
>} else {
>fprintf(stdout, "Opened database successfully\n");
>}
>memset(query,0,200);
>strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
>"key   TEXT PRIMARY KEY   NOT NULL," \
>"valueVARCHAR(100));");
>
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
>
>
>if( lastError != SQLITE_OK ){
>fprintf(stderr, "SQL error: %s\n", zErrMsg);
>sqlite3_free(zErrMsg);
>} else {
>fprintf(stdout, "Table created successfully\n");
>}
>return db;
>}
>
>
>
>int mydef_set(cf_db_t *dbObj,char *key, char **value)
>{
>char *zErrMsg = 0;
>int rc;
>sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value)
>values
>('%s', '%s');",key,*value);
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
>if( lastError != SQLITE_OK ) {
>  fprintf(stderr, "SQL error: %s\n", zErrMsg);
>  sqlite3_free(zErrMsg);
>   } else {
>  fprintf(stdout, "Update done successfully\n");
>   }
>return lastError;
>}
>
>
>int main()
>{
>sqlite3 *db;
>db=mod_init();
>mydef_set(db,"sssi","Hitjkahzdsdhdjksdhjsdhsjfhjsdhfjhsjd bcn
>bsdbgfhjsdgcsdfcbscbshdfgchdsfbbsdfcsfg");
>}
>
>Thanks,
>Ratheendran
>___
>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] segmentation fault in sqlite api call

2018-10-21 Thread Peter da Silva
You're passing a char * to a routine that expects a char **, and then
immediately trying to indirect through it, which means it's taking the
text, treating it as a pointer, and passing the random data it's pointing
to as a string to sqlite.

On Sun., 21 Oct. 2018, 11:55 Ratheendran R,  wrote:

> Hi,
>
> I am a embedded engineer and new to sqlite,we want to use sqlite for our
> local storage instead of file i/o.
>
> I have created a table with key and value records of char type,now if I try
> store a value with string length more than 50 char I get segmentation
> fault,please see the code below and let me know if I can improve it.
>
> sqlite3 *mod_init() {
>
> /* Open database */
> //rc = sqlite3_open("test.db", >db);
> lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL);
> if( lastError ) {
> fprintf(stderr, "Can't open database: %s\n",
> sqlite3_errmsg(dbObj->db));
> free(query);
> return(0);
> } else {
> fprintf(stdout, "Opened database successfully\n");
> }
> memset(query,0,200);
> strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
> "key   TEXT PRIMARY KEY   NOT NULL," \
> "valueVARCHAR(100));");
>
> /* Execute SQL statement */
> lastError = sqlite3_exec(db, query, 0, 0, );
>
>
> if( lastError != SQLITE_OK ){
> fprintf(stderr, "SQL error: %s\n", zErrMsg);
> sqlite3_free(zErrMsg);
> } else {
> fprintf(stdout, "Table created successfully\n");
> }
> return db;
> }
>
>
>
> int mydef_set(cf_db_t *dbObj,char *key, char **value)
> {
> char *zErrMsg = 0;
> int rc;
> sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
> ('%s', '%s');",key,*value);
> /* Execute SQL statement */
> lastError = sqlite3_exec(db, query, 0, 0, );
> if( lastError != SQLITE_OK ) {
>   fprintf(stderr, "SQL error: %s\n", zErrMsg);
>   sqlite3_free(zErrMsg);
>} else {
>   fprintf(stdout, "Update done successfully\n");
>}
> return lastError;
> }
>
>
> int main()
> {
> sqlite3 *db;
> db=mod_init();
> mydef_set(db,"sssi","Hitjkahzdsdhdjksdhjsdhsjfhjsdhfjhsjd bcn
> bsdbgfhjsdgcsdfcbscbshdfgchdsfbbsdfcsfg");
> }
>
> Thanks,
> Ratheendran
> ___
> 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] segmentation fault in sqlite api call

2018-10-21 Thread Larry Brasfield
The code you provided declares and defines a pointer, named ‘db’ in main(), 
which is used with the SQLite API but never made to point to a valid object in 
memory or even to allocated memory.  Hence your segmentation fault.

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


Re: [sqlite] segmentation fault in sqlite api call

2018-10-21 Thread Olivier Mascia
Hi,

mydef_set probably overflows your 'query' variable of which you don't show 
declaration but I guess it is 200 bytes seeing your memset(query,0,200); 
strcpy(query, ...

This above and why this char** buffer in mydef_set prototype?
Think about what your intent was. Compare to what you did (right) for key 
parameter.

Try to stop writing software that sprintf things to fixed sized buffers. 
Especially when the purpose is to dynamically build SQL statements. Learn about 
using parameters in your SQL statement, prepare once and execute many, 
supplying values for the parameters at each run (step).

Hope it will help.
-- 
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia

> Le 21 oct. 2018 à 18:54, Ratheendran R  a écrit :
> 
> Hi,
> 
> I am a embedded engineer and new to sqlite,we want to use sqlite for our
> local storage instead of file i/o.
> 
> I have created a table with key and value records of char type,now if I try
> store a value with string length more than 50 char I get segmentation
> fault,please see the code below and let me know if I can improve it.
> 
> sqlite3 *mod_init() {
> 
>/* Open database */
>//rc = sqlite3_open("test.db", >db);
>lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE |
> SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL);
>if( lastError ) {
>fprintf(stderr, "Can't open database: %s\n",
> sqlite3_errmsg(dbObj->db));
>free(query);
>return(0);
>} else {
>fprintf(stdout, "Opened database successfully\n");
>}
>memset(query,0,200);
>strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
>"key   TEXT PRIMARY KEY   NOT NULL," \
>"valueVARCHAR(100));");
> 
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
> 
> 
>if( lastError != SQLITE_OK ){
>fprintf(stderr, "SQL error: %s\n", zErrMsg);
>sqlite3_free(zErrMsg);
>} else {
>fprintf(stdout, "Table created successfully\n");
>}
> return db;
> }
> 
> 
> 
> int mydef_set(cf_db_t *dbObj,char *key, char **value)
> {
>char *zErrMsg = 0;
>int rc;
>sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
> ('%s', '%s');",key,*value);
>/* Execute SQL statement */
>lastError = sqlite3_exec(db, query, 0, 0, );
>if( lastError != SQLITE_OK ) {
>  fprintf(stderr, "SQL error: %s\n", zErrMsg);
>  sqlite3_free(zErrMsg);
>   } else {
>  fprintf(stdout, "Update done successfully\n");
>   }
>return lastError;
> }
> 
> 
> int main()
> {
>sqlite3 *db;
>db=mod_init();
>mydef_set(db,"sssi","Hitjkahzdsdhdjksdhjsdhsjfhjsdhfjhsjd bcn
> bsdbgfhjsdgcsdfcbscbshdfgchdsfbbsdfcsfg");
> }
> 
> Thanks,
> Ratheendran
> ___
> 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


[sqlite] segmentation fault in sqlite api call

2018-10-21 Thread Ratheendran R
Hi,

I am a embedded engineer and new to sqlite,we want to use sqlite for our
local storage instead of file i/o.

I have created a table with key and value records of char type,now if I try
store a value with string length more than 50 char I get segmentation
fault,please see the code below and let me know if I can improve it.

sqlite3 *mod_init() {

/* Open database */
//rc = sqlite3_open("test.db", >db);
lastError = sqlite3_open_v2("test.db", , SQLITE_OPEN_READWRITE |
SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_NOMUTEX , NULL);
if( lastError ) {
fprintf(stderr, "Can't open database: %s\n",
sqlite3_errmsg(dbObj->db));
free(query);
return(0);
} else {
fprintf(stdout, "Opened database successfully\n");
}
memset(query,0,200);
strcpy(query,"CREATE TABLE IF NOT EXISTS cosmos_db("  \
"key   TEXT PRIMARY KEY   NOT NULL," \
"valueVARCHAR(100));");

/* Execute SQL statement */
lastError = sqlite3_exec(db, query, 0, 0, );


if( lastError != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
} else {
fprintf(stdout, "Table created successfully\n");
}
return db;
}



int mydef_set(cf_db_t *dbObj,char *key, char **value)
{
char *zErrMsg = 0;
int rc;
sprintf(query,"INSERT OR REPLACE INTO cosmos_db (key,value) values
('%s', '%s');",key,*value);
/* Execute SQL statement */
lastError = sqlite3_exec(db, query, 0, 0, );
if( lastError != SQLITE_OK ) {
  fprintf(stderr, "SQL error: %s\n", zErrMsg);
  sqlite3_free(zErrMsg);
   } else {
  fprintf(stdout, "Update done successfully\n");
   }
return lastError;
}


int main()
{
sqlite3 *db;
db=mod_init();
mydef_set(db,"sssi","Hitjkahzdsdhdjksdhjsdhsjfhjsdhfjhsjd bcn
bsdbgfhjsdgcsdfcbscbshdfgchdsfbbsdfcsfg");
}

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


[sqlite] Segmentation fault in 3.22 eval.c under PRAGMA empty_result_callbacks=1

2018-02-14 Thread petern
sqlite> .version
SQLite 3.22.0 2018-01-22 18:45:57
0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1
zlib version 1.2.8
gcc-4.8.4

sqlite> .load eval.so
sqlite> PRAGMA empty_result_callbacks=1;
sqlite> SELECT eval('SELECT 1 WHERE 0');
... Segmentation fault

If a new protection line 35:"if(!argv) return 0;" or equivalent is being
added to 'eval.c', please also consider the enhancement of implementing an
optional 3rd argument eg. eval(X,Y,Z) where Z is the row separator.
eval(X[,Y[,Z]]) with  both optional Y column separator and optional Z row
separator will make eval() more general and useful in all situations.

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread Richard Hipp
Thanks.  I'm still unable to get SQLite 3.15.0 to fail, in any way,
using your schema and data.  Do you have any further hints on how I
can cause the problem to be expressed?

Is assertion fault reliably reproduced on your system?

On 11/1/16, mark  wrote:
> On Tue Nov 01, 2016 at 09:21:04AM -0400, Richard Hipp wrote:
>>
>> The text of the SQL that is being prepared got cut off.  Can you
>> please send me the complete SQL statement that is being run at the
>> point of the error?
>
> INSERT INTO
> func_begin_change(
> author,
> author_contact,
> author_contact_method,
> author_shortname,
> id,
> lang,
> mtime,
> mtimetz,
> parent_id
> )
> VALUES
> (
> ?,
> ?,
> ?,
> ?,
> ?,
> ?,
> ?,
> ?,
> ?
> )
> ;
>
> At least that is what I am passing to Perl's DBD::SQLite prepare()
> method. I am then binding the following values before running execute:
>
> $VAR1 = [
>   'Mark Lawrence',
>   'em...@address.net',
>   'email',
>   'ML',
>   13,
>   'en',
>   '1478010282201',
>   360,
>   undef
> ];
>
> I presume that the underlying DBD driver using SQLite's bind api and
> not replacing '?' with values, but I haven't checked for sure.
>
> --
> Mark Lawrence
>


-- 
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] Segmentation fault on OpenBSD

2016-11-01 Thread nomad
On Tue Nov 01, 2016 at 03:15:43PM +, Simon Slavin wrote:
> 
> On 1 Nov 2016, at 3:14pm, Rob Willett 
> wrote:
> 
> > We use the Perl DBD module all the time. What I would expect to see
> > is [... good stuff ...]
> 
> Ah, thanks for the explanation.  I always had trouble understanding
> Perl's approach to anything.  Hope the OP's problem gets solved.

For trivial value types (e.g. obvious strings and/or numbers) Rob's
explaination is usually all one needs to know:

my $sth = $dbh->prepare('statement with ? and ?');
$sth->execute("some","value");

One can even combine prepare, execute & fetch all in one go:

my @array = $dbh->selectrow_array($statement, \%attr, @bind_values);

Unfortunately I can't always do the above steps due to Perl or DBI or
DBD::SQLite making wrong assumptions about the type of the value being
bound.  If I wanted to store say a phone number string (for example
"+417612341234") or a string composed of integers with a leading zero
(012) and just pass it in naively it could get converted to a plain
number (417612341234 or 12) which is not what I want.

So in those cases I have to bind each value separately, specifying the
type. [ This is usually more of an issue with databases that are more
strongly typed than SQLite. ]

my $sth = $db->prepare('statement with ? and ?');
$sth->bind_param(1, '2016-08-01', SQL_DATETIME);
$sth->bind_param(1, '012', SQL_VARCHAR);
$sth->execute;

In fact my code is always doing the bind_param calls individually
because I have an abstraction layer that does it that way whether I
need it or not. There is probably a performance hit but it is somewhere
below the noise floor.

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread Simon Slavin

On 1 Nov 2016, at 3:14pm, Rob Willett  wrote:

> We use the Perl DBD module all the time. What I would expect to see is [... 
> good stuff ...]

Ah, thanks for the explanation.  I always had trouble understanding Perl's 
approach to anything.  Hope the OP's problem gets solved.

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread Rob Willett

Simon,

We use the Perl DBD module all the time. What I would expect to see is 
(IGNORE THE LINE BREAKS)


my $sth = $dbh->prepare("INSERT INTO
func_begin_change(
author,
author_contact,
author_contact_method,
author_shortname,
id,
lang,
mtime,
mtimetz,
parent_id
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?,
?
)");

followed by

$sth->execute('Mark Lawrence',
  'em...@address.net',
  'email',
  'ML',
  13,
  'en',
  '1478010282201',
  360,
  undef);

The prepare sets the statement up and the execute fills the variables 
in.


Now Mark has probably printed out using Dumper an array in Perl with the 
variables. Thats shown by the use of $VAR1. Anybody who uses Perl uses 
Dumper and is very familiar with the output format :)


Here's what the Perl array could/would/should look like

	['Mark 
Lawrence','em...@address.net','email','ML',13,'en','1478010282201',360,undef]


Now he could call $sth->execute_array(\%attar) rather than 
$sth->execute(var1 , var2) see 
http://search.cpan.org/~timb/DBI-1.636/DBI.pm#execute


We've just checked our Perl libraries and we have never used 
$sth->execute_array as we prefer to be very specific about what we pass 
in.


It would be useful to see the actual Perl itself rather than the 
abstraction in the email. I can't comment on BSD as we don't use it BSD 
at all, but the coding pattern in Perl is pretty standard and very, very 
common. I'd be surprised if this is a problem but you never know.


Rob


On 1 Nov 2016, at 14:57, Simon Slavin wrote:




On 1 Nov 2016, at 2:38pm, mark  wrote:

   VALUES
   (
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?
   )
   ;

At least that is what I am passing to Perl's DBD::SQLite prepare()
method. I am then binding the following values before running 
execute:


   $VAR1 = [
 'Mark Lawrence',
 'em...@address.net',
 'email',
 'ML',
 13,
 'en',
 '1478010282201',
 360,
 undef
   ];


Excuse me.  I don't know Perl, or how it uses its DBD module.  Are you 
binding each of those values (e.g. 'ML') separately, or are you 
binding the whole of $VAR1 as one operation ?


Simon.
___
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] Segmentation fault on OpenBSD

2016-11-01 Thread Simon Slavin

> On 1 Nov 2016, at 2:38pm, mark  wrote:
> 
>VALUES
>(
>?,
>?,
>?,
>?,
>?,
>?,
>?,
>?,
>?
>)
>;
> 
> At least that is what I am passing to Perl's DBD::SQLite prepare()
> method. I am then binding the following values before running execute:
> 
>$VAR1 = [
>  'Mark Lawrence',
>  'em...@address.net',
>  'email',
>  'ML',
>  13,
>  'en',
>  '1478010282201',
>  360,
>  undef
>];

Excuse me.  I don't know Perl, or how it uses its DBD module.  Are you binding 
each of those values (e.g. 'ML') separately, or are you binding the whole of 
$VAR1 as one operation ?

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread mark
On Tue Nov 01, 2016 at 09:21:04AM -0400, Richard Hipp wrote:
> 
> The text of the SQL that is being prepared got cut off.  Can you
> please send me the complete SQL statement that is being run at the
> point of the error?

INSERT INTO
func_begin_change(
author,
author_contact,
author_contact_method,
author_shortname,
id,
lang,
mtime,
mtimetz,
parent_id
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?,
?
)
;

At least that is what I am passing to Perl's DBD::SQLite prepare()
method. I am then binding the following values before running execute:

$VAR1 = [
  'Mark Lawrence',
  'em...@address.net',
  'email',
  'ML',
  13,
  'en',
  '1478010282201',
  360,
  undef
];

I presume that the underlying DBD driver using SQLite's bind api and
not replacing '?' with values, but I haven't checked for sure.

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread Richard Hipp
On 10/31/16, mark  wrote:
> #18 0x17d970826118 in sqlite3RunParser (pParse=0x7f7e9200,
> zSql=0x17db9b16a600 "INSERT INTO\nfunc_begin_change(\n
> author,\nauthor_contact,\nauthor_contact_method,\n
> author_shortname,\nid,\nlang,\nmtime,\n
> mtimetz,\npa"..., pzErrMsg=0x7f7e9468) at sqlite3.c:137350

The text of the SQL that is being prepared got cut off.  Can you
please send me the complete SQL statement that is being run at the
point of the error?

-- 
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] Segmentation fault on OpenBSD

2016-11-01 Thread Richard Hipp
On 10/31/16, mark  wrote:
> #3  0x17d9707fb288 in valueFromExpr (db=0x17dbbac8e808,
> pExpr=0x17dc0252b288, enc=1 '\001', affinity=68 'D',
> ppVal=0x7f7e7f08,
> pCtx=0x7f7e7f70) at sqlite3.c:70020
> #4  0x17d9707fbaa0 in stat4ValueFromExpr (pParse=0x17db76d8fc08,
> pExpr=)
> at sqlite3.c:70249

I need to see your sqlite_stat1 and sqlite_stat4 tables.  You can do
this by sending me the output of

 sqlite3 yourdb.db .fullschema

The sqlite_stat4 table contains actual samples from your database, so
you might want to send the results above via private email.

-- 
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] Segmentation fault on OpenBSD

2016-11-01 Thread mark
On Tue Nov 01, 2016 at 02:21:02AM +0100, mark wrote:

> assertion "0" failed: file "sqlite3.c", line 70020, function
> "valueFromExpr"

I read the source code a little further and found that the NEVER at
line 70020 is actually a macro:

if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;

That macro resolves to an assert, which is failing because op: 

>   (gdb) info locals
>   op = 157
>   zVal = Variable "zVal" is not available.

is the same as TK_REGISTER:

$ grep 'define TK_REGISTER' sqlite3.c
#define TK_REGISTER   157

op then gets set to pExpr->op2 (0 - NULL?) which does not appear to be
a valid TK_* value.

That's about as far as I can go.

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


Re: [sqlite] Segmentation fault on OpenBSD

2016-11-01 Thread mark
On Mon Oct 31, 2016 at 05:42:32PM -0400, Richard Hipp wrote:
> On 10/31/16, mark  wrote:
> > On Mon Oct 31, 2016 at 04:04:00PM -0400, Richard Hipp wrote:
> >> Is this reproducible?
> >
> > Yes... in that I can reliably get it to segfault. Duplicating the build
> > and/or statements leading up to the fault outside of my environment
> > is not so easy. Unless I make the virtual machine image available to
> > you somehow...
> 
> I cannot reproduce the problem on Linux.  Even running under valgrind
> shows no issues.

I can no longer reproduce the original segmentation fault. I still have
errors (back to aborting again) so I'll just follow this through
wherever it leads to.

> Can you please recompile using -DSQLITE_DEBUG and try again.

For completeness here are the rest of the options I'm using:

-DSQLITE_DEBUG
-DSQLITE_ENABLE_COLUMN_METADATA
-DSQLITE_ENABLE_FTS3_PARENTHESIS
-DSQLITE_ENABLE_FTS4
-DSQLITE_ENABLE_FTS5
-DSQLITE_ENABLE_JSON1
-DSQLITE_ENABLE_RTREE
-DSQLITE_ENABLE_STAT3
-DSQLITE_ENABLE_STAT4
-DSQLITE_OMIT_LOAD_EXTENSION

I see one warning during compilation:

sqlite3.c: In function 'sqlite3VdbeExec':
sqlite3.c:78265: warning: comparison is always true due to limited 
range of data type

The sqlite3.c source file should be the one that is here:

https://api.metacpan.org/source/ISHIGAKI/DBD-SQLite-1.51_06/sqlite3.c

> If that works, please insert an extra SQL statement just before the
> SQL statement that is causing the problem, that says:
> 
>  PRAGMA debug=ON;

Even with -DSQLITE_DEBUG the "debug" pragma doesn't seem to do anything
for me (and I can't find it in the documentation). Using "vdbe_debug"
(perhaps what you meant?) I now see the following:

SQL: [PRAGMA
vdbe_debug=on
;]
VDBE Program Listing:
   0 Init 010   00 Start at 1
   1 Expire   000   00 
   2 Halt 000   00 
VDBE Trace:
   0 Init 010   00 Start at 1
SQL-trace: PRAGMA
vdbe_debug=on
;
   1 Expire   000   00 
   2 Halt 000   00 
assertion "0" failed: file "sqlite3.c", line 70020, function "valueFromExpr"
Abort trap (core dumped)

I'm not sure about the line numbers. 70020 in my source (looking at the
file with vim) is not an assert. The backtrace looks like this:

#0  0x17dc6b94f68a in thrkill () at :2
#1  0x17dc6b9223e9 in *_libc_abort ()
at /usr/src/lib/libc/stdlib/abort.c:52
#2  0x17dc6b924e84 in *_libc___assert2 (file=)
at /usr/src/lib/libc/gen/assert.c:52
#3  0x17d9707fb288 in valueFromExpr (db=0x17dbbac8e808, 
pExpr=0x17dc0252b288, enc=1 '\001', affinity=68 'D', 
ppVal=0x7f7e7f08, 
pCtx=0x7f7e7f70) at sqlite3.c:70020
#4  0x17d9707fbaa0 in stat4ValueFromExpr (pParse=0x17db76d8fc08, pExpr=)
at sqlite3.c:70249
#5  0x17d9707fbbdb in sqlite3Stat4ProbeSetValue (pParse=0x17db76d8fc08, 
pIdx=0x17dbe04aab08, ppRec=) at sqlite3.c:70316
#6  0x17d97080b136 in whereEqualScanEst (pParse=0x17db76d8fc08, 
pBuilder=0x7f7e8700, pExpr=) at sqlite3.c:129373
#7  0x17d97080e776 in whereLoopAddBtreeIndex (pBuilder=0x7f7e8700, 
pSrc=0x17dc0252b310, pProbe=0x17dbe04aab08, nInMul=0) at 
sqlite3.c:130285
#8  0x17d97080f327 in whereLoopAddBtree (pBuilder=0x7f7e8700, 
mPrereq=0) at sqlite3.c:130713
#9  0x17d970810357 in sqlite3WhereBegin (pParse=0x17db76d8fc08, 
pTabList=0x17dc0252b308, pWhere=) at sqlite3.c:131185
#10 0x17d9708203c6 in fkScanChildren (pParse=0x17db76d8fc08, 
pSrc=0x17dc0252b308, pTab=0x17dc3f7f6a08, pIdx=0x0, 
pFKey=0x17dbd9f4ae88, 
aiCol=0x0, regData=11, nIncr=-1) at sqlite3.c:106565
#11 0x17d970837f22 in sqlite3FkCheck (pParse=0x17db76d8fc08, 
pTab=0x17dc3f7f6a08, regOld=0, regNew=11, aChange=0x0, bChngRowid=0)
at sqlite3.c:106943
#12 0x17d97083ad6d in sqlite3Insert (pParse=0x17db76d8fc08, 
pTabList=0x17dc0252d688, pSelect=0x17dc02533f88, 
pColumn=0x17dc02534888, 
onError=) at sqlite3.c:108341
#13 0x17d97083b670 in getRowTrigger (pParse=0x7f7e9200, 
pTrigger=0x17dbfda80208, pTab=) at sqlite3.c:120948
#14 0x17d97083babc in sqlite3CodeRowTriggerDirect 
(pParse=0x7f7e9200, 
p=0x17dbfda80208, pTab=0x17dba8948208, reg=-10, orconf=10, 
ignoreJump=-1)
at sqlite3.c:121176
#15 0x17d97083bd44 in sqlite3CodeRowTrigger (pParse=0x7f7e9200, 
pTrigger=0x6, op=108, pChanges=0x0, tr_tm=2, pTab=0x17dba8948208, 
reg=-10, 
orconf=10, ignoreJump=-1) at sqlite3.c:121270
#16 0x17d97083ae32 in sqlite3Insert (pParse=0x7f7e9200, 

Re: [sqlite] Segmentation fault on OpenBSD

2016-10-31 Thread Richard Hipp
On 10/31/16, mark  wrote:
> On Mon Oct 31, 2016 at 04:04:00PM -0400, Richard Hipp wrote:
>> Is this reproducible?
>
> Yes... in that I can reliably get it to segfault. Duplicating the build
> and/or statements leading up to the fault outside of my environment
> is not so easy. Unless I make the virtual machine image available to
> you somehow...

I cannot reproduce the problem on Linux.  Even running under valgrind
shows no issues.

Can you please recompile using -DSQLITE_DEBUG and try again.

If that works, please insert an extra SQL statement just before the
SQL statement that is causing the problem, that says:

 PRAGMA debug=ON;



-- 
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] Segmentation fault on OpenBSD

2016-10-31 Thread Richard Hipp
Is this reproducible?

Can you share with us the schema of the database file that was
connected when this error occurred?

On 10/31/16, mark  wrote:
> Operating system:  OpenBSD 6.0
> DBD::SQLite:   1.51_06
> sqlite:3.15.0
>
> Program received signal SIGSEGV, Segmentation fault.
> sqlite3Step (p=0xb1480c37e08) at sqlite3.c:82102
> 82102   pCrsr = pC->uc.pCursor;
>
> (gdb) list
> 82097
> 82098 assert( pOp->p1>=0 && pOp->p1nCursor );
> 82099 pC = p->apCsr[pOp->p1];
> 82100 assert( pC!=0 );
> 82101 assert( pC->eCurType==CURTYPE_BTREE );
> 82102 pCrsr = pC->uc.pCursor;
> 82103 res = 0;
> 82104 assert( pCrsr!=0 );
> 82105 rc = sqlite3BtreeLast(pCrsr, );
> 82106 pC->nullRow = (u8)res;
>
> (gdb) backtrace
> #0  sqlite3Step (p=0xb1480c37e08) at sqlite3.c:82102
> #1  0x0b12443083c2 in sqlite3_step (pStmt=0xb1480c37e08) at
> sqlite3.c:75763
> #2  0x0b12442a4499 in sqlite_st_execute (sth=0xb1517a8c860,
> imp_sth=0xb14c73a6c00) at dbdimp.c:1038
> #3  0x0b1244297733 in XS_DBD__SQLite__st_execute (cv=) at SQLite.xsi:614
> #4  0x0b124435287e in XS_DBI_dispatch (cv=0xb14fd2eaec8) at DBI.xs:3781
> #5  0x0b12443e8ab3 in Perl_pp_entersub () at pp_hot.c:2794
> #6  0x0b12443e1b0d in Perl_runops_standard () at run.c:42
> #7  0x0b1244384922 in perl_run (my_perl=) at perl.c:2460
> #8  0x0b1244242a5d in main (argc=5, argv=0x7f7ce088) at
> bundle.c:15984
>
> (gdb) print *p
> $1 = {db = 0xb145e66b008, pPrev = 0x0, pNext = 0x0, pParse = 0x7f7cd610,
>   nVar = 1, nzVar = 0, magic = 770837923, nMem = 190, nCursor = 45,
>   cacheCtr = 1, pc = 0, rc = 0, nChange = 0, iStatement = 1, iCurrentTime =
> 0,
>   nFkConstraint = 0, nStmtDefCons = 1, nStmtDefImmCons = 0,
>   aOp = 0xb146d74d008, aMem = 0xb148a5c8070, apArg = 0xb14bcaac698,
>   aColName = 0x0, pResultSet = 0x0, zErrMsg = 0x0, apCsr = 0xb148a5caa00,
>   aVar = 0xb14bcaac698, azVar = 0x0, startTime = 0, nOp = 508, nResColumn =
> 0,
>   errorAction = 2 '\002', minWriteFileFormat = 4 '\004', expired = 0,
>   doingRerun = 0, explain = 0, changeCntOn = 1, runOnlyOnce = 0,
>   usesStmtJournal = 1, readOnly = 0, bIsReader = 1, isPrepareV2 = 1,
>   btreeMask = 1, lockMask = 0, aCounter = {42, 227, 2, 0, 0},
>   zSql = 0xb14b6dc7188 "INSERT INTO\nfunc_merge_deltas(\nmerge\n
>)\nVALUES\n(\n?\n)\n;", pFree = 0x0, pFrame =
> 0xb148a5c8008,
>   pDelFrame = 0x0, nFrame = 5, expmask = 0, pProgram = 0xb146b8be548,
>   pAuxData = 0x0}
>
> --
> Mark Lawrence
> ___
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
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] Segmentation fault on OpenBSD

2016-10-31 Thread mark
Operating system:  OpenBSD 6.0
DBD::SQLite:   1.51_06
sqlite:3.15.0

Program received signal SIGSEGV, Segmentation fault.
sqlite3Step (p=0xb1480c37e08) at sqlite3.c:82102
82102 pCrsr = pC->uc.pCursor;

(gdb) list
82097
82098 assert( pOp->p1>=0 && pOp->p1nCursor );
82099 pC = p->apCsr[pOp->p1];
82100 assert( pC!=0 );
82101 assert( pC->eCurType==CURTYPE_BTREE );
82102 pCrsr = pC->uc.pCursor;
82103 res = 0;
82104 assert( pCrsr!=0 );
82105 rc = sqlite3BtreeLast(pCrsr, );
82106 pC->nullRow = (u8)res;

(gdb) backtrace
#0  sqlite3Step (p=0xb1480c37e08) at sqlite3.c:82102
#1  0x0b12443083c2 in sqlite3_step (pStmt=0xb1480c37e08) at sqlite3.c:75763
#2  0x0b12442a4499 in sqlite_st_execute (sth=0xb1517a8c860, 
imp_sth=0xb14c73a6c00) at dbdimp.c:1038
#3  0x0b1244297733 in XS_DBD__SQLite__st_execute (cv=) at SQLite.xsi:614
#4  0x0b124435287e in XS_DBI_dispatch (cv=0xb14fd2eaec8) at DBI.xs:3781
#5  0x0b12443e8ab3 in Perl_pp_entersub () at pp_hot.c:2794
#6  0x0b12443e1b0d in Perl_runops_standard () at run.c:42
#7  0x0b1244384922 in perl_run (my_perl=) at perl.c:2460
#8  0x0b1244242a5d in main (argc=5, argv=0x7f7ce088) at bundle.c:15984

(gdb) print *p
$1 = {db = 0xb145e66b008, pPrev = 0x0, pNext = 0x0, pParse = 0x7f7cd610, 
  nVar = 1, nzVar = 0, magic = 770837923, nMem = 190, nCursor = 45, 
  cacheCtr = 1, pc = 0, rc = 0, nChange = 0, iStatement = 1, iCurrentTime = 0, 
  nFkConstraint = 0, nStmtDefCons = 1, nStmtDefImmCons = 0, 
  aOp = 0xb146d74d008, aMem = 0xb148a5c8070, apArg = 0xb14bcaac698, 
  aColName = 0x0, pResultSet = 0x0, zErrMsg = 0x0, apCsr = 0xb148a5caa00, 
  aVar = 0xb14bcaac698, azVar = 0x0, startTime = 0, nOp = 508, nResColumn = 0, 
  errorAction = 2 '\002', minWriteFileFormat = 4 '\004', expired = 0, 
  doingRerun = 0, explain = 0, changeCntOn = 1, runOnlyOnce = 0, 
  usesStmtJournal = 1, readOnly = 0, bIsReader = 1, isPrepareV2 = 1, 
  btreeMask = 1, lockMask = 0, aCounter = {42, 227, 2, 0, 0}, 
  zSql = 0xb14b6dc7188 "INSERT INTO\nfunc_merge_deltas(\nmerge\n
)\nVALUES\n(\n?\n)\n;", pFree = 0x0, pFrame = 0xb148a5c8008, 
  pDelFrame = 0x0, nFrame = 5, expmask = 0, pProgram = 0xb146b8be548, 
  pAuxData = 0x0}

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


Re: [sqlite] Segmentation fault in command line using aggregate function in column default value

2014-08-05 Thread Clemens Ladisch
Zsbán Ambrus wrote:
> CREATE TABLE tab(amt DEFAULT (max(1)));

SQLite also accepts parameters:

  CREATE TABLE t(x DEFAULT(?));

(Other places like CHECK constraints do check for this, so this appears
to be an oversight.)


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


Re: [sqlite] Segmentation fault in command line using aggregate function in column default value

2014-08-05 Thread Richard Hipp
On Tue, Aug 5, 2014 at 4:55 PM, Richard Hipp  wrote:

>
>
>
> On Tue, Aug 5, 2014 at 4:15 PM, Zsbán Ambrus  wrote:
>
>> Dear sqlite3 maintainers,
>>
>> I've got a segmentation fault when trying to execute the following two
>> statements in the sqlite 3.8.5 command line program:
>>
>> CREATE TABLE tab(amt DEFAULT (max(1))); INSERT INTO tab DEFAULT VALUES;
>>
>
> The ticket is here: www.sqlite.org/src/tktview/3a88d85f3670
>

Preliminary fix here:  http://www.sqlite.org/src/info/29ba812825bf
We'll do more testing before closing the ticket.


>
>
>
>>
>> I believe this is a bug, because the vanilla command line should not
>> segfault from an invalid command, and should give some error message
>> instead.  The statement has an error because max(1) is a call to an
>> aggregate function so should only appear in a result column of a
>> SELECT statement or similar contexts, not in a column default.
>>
>> I don't load any database for this, so the command line starts from a
>> new temporary database with empty schema and default settings.
>>
>> The command line reports its version as "SQLite version 3.8.5
>> 2014-06-04 14:06:34".  It is running on a debian-based linux x86-64
>> machine.  I have built it from the sqlite-amalgamation-3080500 source
>> to x86-64 application with a vanilla gcc 4.8.1 with the following
>> compiler command line:
>>
>> gcc -Wall -ldl -lpthread -O2 -o sqlite3 shell.c sqlite3.c
>>
>> If you need any further information for reproducing this bug, please
>> contact me.
>>
>> -- Ambrus
>> ___
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>
>
>
> --
> D. Richard Hipp
> d...@sqlite.org
>



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


Re: [sqlite] Segmentation fault in command line using aggregate function in column default value

2014-08-05 Thread Simon Slavin

On 5 Aug 2014, at 9:15pm, Zsbán Ambrus  wrote:

> CREATE TABLE tab(amt DEFAULT (max(1))); INSERT INTO tab DEFAULT VALUES;

How on earth did you find that ?

Nice catch, by the way.  If Dr. Hipp is correct, that's a bug which has existed 
for longer than 8 years, or probably ever since SQLite3 existed.

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


Re: [sqlite] Segmentation fault in command line using aggregate function in column default value

2014-08-05 Thread Richard Hipp
On Tue, Aug 5, 2014 at 4:15 PM, Zsbán Ambrus  wrote:

> Dear sqlite3 maintainers,
>
> I've got a segmentation fault when trying to execute the following two
> statements in the sqlite 3.8.5 command line program:
>
> CREATE TABLE tab(amt DEFAULT (max(1))); INSERT INTO tab DEFAULT VALUES;
>

The ticket is here: www.sqlite.org/src/tktview/3a88d85f3670



>
> I believe this is a bug, because the vanilla command line should not
> segfault from an invalid command, and should give some error message
> instead.  The statement has an error because max(1) is a call to an
> aggregate function so should only appear in a result column of a
> SELECT statement or similar contexts, not in a column default.
>
> I don't load any database for this, so the command line starts from a
> new temporary database with empty schema and default settings.
>
> The command line reports its version as "SQLite version 3.8.5
> 2014-06-04 14:06:34".  It is running on a debian-based linux x86-64
> machine.  I have built it from the sqlite-amalgamation-3080500 source
> to x86-64 application with a vanilla gcc 4.8.1 with the following
> compiler command line:
>
> gcc -Wall -ldl -lpthread -O2 -o sqlite3 shell.c sqlite3.c
>
> If you need any further information for reproducing this bug, please
> contact me.
>
> -- Ambrus
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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


[sqlite] Segmentation fault in command line using aggregate function in column default value

2014-08-05 Thread Zsbán Ambrus
Dear sqlite3 maintainers,

I've got a segmentation fault when trying to execute the following two
statements in the sqlite 3.8.5 command line program:

CREATE TABLE tab(amt DEFAULT (max(1))); INSERT INTO tab DEFAULT VALUES;

I believe this is a bug, because the vanilla command line should not
segfault from an invalid command, and should give some error message
instead.  The statement has an error because max(1) is a call to an
aggregate function so should only appear in a result column of a
SELECT statement or similar contexts, not in a column default.

I don't load any database for this, so the command line starts from a
new temporary database with empty schema and default settings.

The command line reports its version as "SQLite version 3.8.5
2014-06-04 14:06:34".  It is running on a debian-based linux x86-64
machine.  I have built it from the sqlite-amalgamation-3080500 source
to x86-64 application with a vanilla gcc 4.8.1 with the following
compiler command line:

gcc -Wall -ldl -lpthread -O2 -o sqlite3 shell.c sqlite3.c

If you need any further information for reproducing this bug, please contact me.

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


Re: [sqlite] Segmentation Fault With Trigger

2013-10-15 Thread Dominique Pellé
techi eth wrote:

You should compile your code & sqlite3.c with -g -O0 when
sending a stack trace.

Most likely, the bug is in your program. Since you're on Linux,
try running with valgrind memcheck tool to find bugs (access
to free memory, uninitialized memory, etc.)

If you compile with clang-3.3 or newer, or gcc-4.8.* or newer, you
can also compile & link with -fsanitize=address to find bugs
(much quicker than using valgrind if your program is slow).

But the best is to try both (valgrind & gcc/clang address sanitizer,
not at the same time) since they can find different bugs:
* only valgrind will find uninitialized memory access
* only the address sanitizer will find global and stack overflows
* both will find other kind of errors (double free, use of freed memory...)

Dominique


> Please provide me hint to solve the issue.
>
>
> Thanks..
>
>
> On Fri, Oct 11, 2013 at 7:58 PM, techi eth  wrote:
>
>> It is giving same trace what i have sent last time.
>>
>> It is possible by some one to send test code snapshot of scenario of
>> selecting user defined function while trigger execution.
>>
>> Thanks a lot...
>>
>>
>> On Fri, Oct 11, 2013 at 7:41 PM, Richard Hipp  wrote:
>>
>>> On Fri, Oct 11, 2013 at 10:06 AM, techi eth  wrote:
>>>
>>> > Please provide some hint.
>>> >
>>>
>>> Recompile with -O0 and -g and then post the stack trace after the
>>> segfault.
>>>
>>> --
>>> D. Richard Hipp
>>> d...@sqlite.org
>>> ___
>>> 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] Segmentation Fault With Trigger

2013-10-15 Thread Ryan Johnson
I'm not an sqlite3 dev, but I don't think you'll get much help until you 
provide enough information for somebody to see what is going wrong. You 
were already asked to provide a backtrace from a debug-compiled sqlite3 
library (the backtrace you sent is all but useless).


A self-contained .c file that demonstrates the problem would be even 
better. For example, without knowing what your user-defined function 
does, we have to assume it is full of memory corruption bugs that cause 
the problems you experience.


Ryan

On 15/10/2013 12:12 AM, techi eth wrote:

Please provide me hint to solve the issue.


Thanks..


On Fri, Oct 11, 2013 at 7:58 PM, techi eth  wrote:


It is giving same trace what i have sent last time.

It is possible by some one to send test code snapshot of scenario of
selecting user defined function while trigger execution.

Thanks a lot...


On Fri, Oct 11, 2013 at 7:41 PM, Richard Hipp  wrote:


On Fri, Oct 11, 2013 at 10:06 AM, techi eth  wrote:


Please provide some hint.


Recompile with -O0 and -g and then post the stack trace after the
segfault.

--
D. Richard Hipp
d...@sqlite.org
___
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] Segmentation Fault With Trigger

2013-10-14 Thread techi eth
Please provide me hint to solve the issue.


Thanks..


On Fri, Oct 11, 2013 at 7:58 PM, techi eth  wrote:

> It is giving same trace what i have sent last time.
>
> It is possible by some one to send test code snapshot of scenario of
> selecting user defined function while trigger execution.
>
> Thanks a lot...
>
>
> On Fri, Oct 11, 2013 at 7:41 PM, Richard Hipp  wrote:
>
>> On Fri, Oct 11, 2013 at 10:06 AM, techi eth  wrote:
>>
>> > Please provide some hint.
>> >
>>
>> Recompile with -O0 and -g and then post the stack trace after the
>> segfault.
>>
>> --
>> D. Richard Hipp
>> d...@sqlite.org
>> ___
>> 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] Segmentation Fault With Trigger

2013-10-11 Thread techi eth
It is giving same trace what i have sent last time.

It is possible by some one to send test code snapshot of scenario of
selecting user defined function while trigger execution.

Thanks a lot...


On Fri, Oct 11, 2013 at 7:41 PM, Richard Hipp  wrote:

> On Fri, Oct 11, 2013 at 10:06 AM, techi eth  wrote:
>
> > Please provide some hint.
> >
>
> Recompile with -O0 and -g and then post the stack trace after the segfault.
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> 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] Segmentation Fault With Trigger

2013-10-11 Thread techi eth
Data Info is not an problem.I am passing data information for building
query before passing to sqlite exec function.If i remove trigger for insert
then my code is working perfectly fine.

My assumption is it is due to selecting function  during trigger.Please
suggest hint by looking sequence provide by me.

Thanks


On Fri, Oct 11, 2013 at 7:41 PM, Stephan Beal  wrote:

> On Fri, Oct 11, 2013 at 4:06 PM, techi eth  wrote:
>
> > > #4  0x778e1127 in SqliteTestInsert (SQLitePrivate=0x602300,
> > > TableName_p=0x4019a0 "dbTestTbl", DataInfoList=0x4)
> >
>
> There's the problem: DataInfoList is an invalid pointer. i have no idea
> what that is, but it's not part of sqlite3's sources.
>
> --
> - stephan beal
> http://wanderinghorse.net/home/stephan/
> http://gplus.to/sgbeal
> ___
> 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] Segmentation Fault With Trigger

2013-10-11 Thread Stephan Beal
On Fri, Oct 11, 2013 at 4:06 PM, techi eth  wrote:

> > #4  0x778e1127 in SqliteTestInsert (SQLitePrivate=0x602300,
> > TableName_p=0x4019a0 "dbTestTbl", DataInfoList=0x4)
>

There's the problem: DataInfoList is an invalid pointer. i have no idea
what that is, but it's not part of sqlite3's sources.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault With Trigger

2013-10-11 Thread Richard Hipp
On Fri, Oct 11, 2013 at 10:06 AM, techi eth  wrote:

> Please provide some hint.
>

Recompile with -O0 and -g and then post the stack trace after the segfault.

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


Re: [sqlite] Segmentation Fault With Trigger

2013-10-11 Thread techi eth
Please provide some hint.I have added some more details about function
definition & query.

/* Create function definition */
static void Test(sqlite3_context *context, int argc, sqlite3_value **argv)
{
printf ("Trigger Function Called\n");
if (argc == 1) {
char *text = sqlite3_value_text(argv[0]);
if (text && text[0]) {
  char result[2];
  result[0] = text[0]; result[1] = '\0';
  sqlite3_result_text(context, result, -1, SQLITE_TRANSIENT);
  return;
}
}
sqlite3_result_null(context);
}
/*Create Function */
sqlite3_create_function(Handler, "Test",1, SQLITE_UTF8, NULL, , NULL,
NULL);

/*Create Trigger Query */
create trigger TestTrigger after insert on dbTestTbl for each row begin
SELECT Test (new.RowId) from dbTestTbl; end;


On Fri, Oct 11, 2013 at 5:55 PM, techi eth  wrote:

> Please find below :
>
> #0  0x7fffe0b8 in ?? ()
>
> #1  0x776988f6 in ?? () from
> /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
>
> #2  0x7769e451 in sqlite3_step () from
> /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
>
> #3  0x776a1e4c in sqlite3_exec () from
> /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
>
> #4  0x778e1127 in SqliteTestInsert (SQLitePrivate=0x602300,
> TableName_p=0x4019a0 "dbTestTbl", DataInfoList=0x4)
>
> #5  0x00400d58 in TEST_SqliteTestInsert (RowID=) at
> sqlite3_test.c:340
>
> #6  main (argc=, args=) at sqlite3_test.c:922
>
> Thanks
>
>
> On Fri, Oct 11, 2013 at 5:35 PM, Richard Hipp  wrote:
>
>> On Fri, Oct 11, 2013 at 7:57 AM, techi eth  wrote:
>>
>> > Hi,
>> >
>> > I am getting segmentation fault while executing query in sqlite3. [Linux
>> > OS].
>> >
>>
>> Can you send us a stack trace?
>>
>>
>> >
>> > Find below sequence.
>> >
>> > // Getting SQLiteHandler
>> >
>> > OpenConnection ();
>> >
>> > //Creating user defined function “Test”
>> >
>> > sqlite3_create_function(SQLiteHandler, "Test",1, SQLITE_UTF8, NULL,
>> ,
>> > NULL, NULL)
>> >
>> > //Creating table,Below is DDL
>> >
>> > CREATE TABLE dbTestTbl (
>> >
>> > RowID   INTEGER PRIMARY KEY AUTOINCREMENT,
>> >
>> > ParamaterID INTEGER,
>> >
>> > ParamaterValue  TEXT
>> >
>> > );
>> >
>> > //Createatd Trigger,Below is DDL
>> >
>> > CREATE TRIGGER TestTrigger
>> >
>> >AFTER INSERT ON dbTestTbl
>> >
>> >FOR EACH ROW
>> >
>> > BEGIN
>> >
>> > SELECT Test( RowID )
>> >
>> >   FROM dbTestTbl;
>> >
>> > END;
>> >
>> > // INSERT INTO dbTestTbl
>> >
>> > Please suggest what is wrong defined here.
>> >
>> > Thanks
>> > ___
>> > sqlite-users mailing list
>> > sqlite-users@sqlite.org
>> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>> >
>>
>>
>>
>> --
>> D. Richard Hipp
>> d...@sqlite.org
>> ___
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault With Trigger

2013-10-11 Thread techi eth
Please find below :

#0  0x7fffe0b8 in ?? ()

#1  0x776988f6 in ?? () from
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0

#2  0x7769e451 in sqlite3_step () from
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0

#3  0x776a1e4c in sqlite3_exec () from
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0

#4  0x778e1127 in SqliteTestInsert (SQLitePrivate=0x602300,
TableName_p=0x4019a0 "dbTestTbl", DataInfoList=0x4)

#5  0x00400d58 in TEST_SqliteTestInsert (RowID=) at
sqlite3_test.c:340

#6  main (argc=, args=) at sqlite3_test.c:922

Thanks


On Fri, Oct 11, 2013 at 5:35 PM, Richard Hipp  wrote:

> On Fri, Oct 11, 2013 at 7:57 AM, techi eth  wrote:
>
> > Hi,
> >
> > I am getting segmentation fault while executing query in sqlite3. [Linux
> > OS].
> >
>
> Can you send us a stack trace?
>
>
> >
> > Find below sequence.
> >
> > // Getting SQLiteHandler
> >
> > OpenConnection ();
> >
> > //Creating user defined function “Test”
> >
> > sqlite3_create_function(SQLiteHandler, "Test",1, SQLITE_UTF8, NULL,
> ,
> > NULL, NULL)
> >
> > //Creating table,Below is DDL
> >
> > CREATE TABLE dbTestTbl (
> >
> > RowID   INTEGER PRIMARY KEY AUTOINCREMENT,
> >
> > ParamaterID INTEGER,
> >
> > ParamaterValue  TEXT
> >
> > );
> >
> > //Createatd Trigger,Below is DDL
> >
> > CREATE TRIGGER TestTrigger
> >
> >AFTER INSERT ON dbTestTbl
> >
> >FOR EACH ROW
> >
> > BEGIN
> >
> > SELECT Test( RowID )
> >
> >   FROM dbTestTbl;
> >
> > END;
> >
> > // INSERT INTO dbTestTbl
> >
> > Please suggest what is wrong defined here.
> >
> > Thanks
> > ___
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> >
>
>
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault With Trigger

2013-10-11 Thread Richard Hipp
On Fri, Oct 11, 2013 at 7:57 AM, techi eth  wrote:

> Hi,
>
> I am getting segmentation fault while executing query in sqlite3. [Linux
> OS].
>

Can you send us a stack trace?


>
> Find below sequence.
>
> // Getting SQLiteHandler
>
> OpenConnection ();
>
> //Creating user defined function “Test”
>
> sqlite3_create_function(SQLiteHandler, "Test",1, SQLITE_UTF8, NULL, ,
> NULL, NULL)
>
> //Creating table,Below is DDL
>
> CREATE TABLE dbTestTbl (
>
> RowID   INTEGER PRIMARY KEY AUTOINCREMENT,
>
> ParamaterID INTEGER,
>
> ParamaterValue  TEXT
>
> );
>
> //Createatd Trigger,Below is DDL
>
> CREATE TRIGGER TestTrigger
>
>AFTER INSERT ON dbTestTbl
>
>FOR EACH ROW
>
> BEGIN
>
> SELECT Test( RowID )
>
>   FROM dbTestTbl;
>
> END;
>
> // INSERT INTO dbTestTbl
>
> Please suggest what is wrong defined here.
>
> Thanks
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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


[sqlite] Segmentation Fault With Trigger

2013-10-11 Thread techi eth
Hi,

I am getting segmentation fault while executing query in sqlite3. [Linux
OS].

Find below sequence.

// Getting SQLiteHandler

OpenConnection ();

//Creating user defined function “Test”

sqlite3_create_function(SQLiteHandler, "Test",1, SQLITE_UTF8, NULL, ,
NULL, NULL)

//Creating table,Below is DDL

CREATE TABLE dbTestTbl (

RowID   INTEGER PRIMARY KEY AUTOINCREMENT,

ParamaterID INTEGER,

ParamaterValue  TEXT

);

//Createatd Trigger,Below is DDL

CREATE TRIGGER TestTrigger

   AFTER INSERT ON dbTestTbl

   FOR EACH ROW

BEGIN

SELECT Test( RowID )

  FROM dbTestTbl;

END;

// INSERT INTO dbTestTbl

Please suggest what is wrong defined here.

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


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread kenichi ishigaki
Thank you for the fix!

Kenichi Ishigaki

2013/8/30 Marc L. Allen <mlal...@outsitenetworks.com>:
> Thanks... that certainly clarifies it.  Also, thanks to Dan who responded 
> similarly.
>
> -Original Message-
> From: sqlite-users-boun...@sqlite.org 
> [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Richard Hipp
> Sent: Thursday, August 29, 2013 11:58 AM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] segmentation fault with 3.8.0
>
> On Thu, Aug 29, 2013 at 11:47 AM, Marc L. Allen <mlal...@outsitenetworks.com
>> wrote:
>
>> Silly question.. I looked at the fix.  Why ignore indexes with greater
>> than 4 fields?  Isn't that a bit risky?  Wouldn't it be better to
>> ignore the fields after the 4th one for planning?
>>
>
> The whereShortCut() routine is merely an optimization.  It provides a quick 
> plan for the common case of a single-table query using an equality constraint 
> on a PRIMARY KEY or UNIQUE index.  Anything that falls through
> whereShortCut() goes into the regular query planner and will get analyzed 
> thoroughly there.
>
> You could omit the whereShortCut() routine entirely and SQLite would still 
> give the correct answer.  The only downside is that sqlite3_prepare_v2() 
> would run slightly slower in the common case.
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>
> This email and any attachments are only for use by the intended recipient(s) 
> and may contain legally privileged, confidential, proprietary or otherwise 
> private information. Any unauthorized use, reproduction, dissemination, 
> distribution or other disclosure of the contents of this e-mail or its 
> attachments is strictly prohibited. If you have received this email in error, 
> please notify the sender immediately and delete the original.
> ___
> 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] segmentation fault with 3.8.0

2013-08-29 Thread Marc L. Allen
Thanks... that certainly clarifies it.  Also, thanks to Dan who responded 
similarly.

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Richard Hipp
Sent: Thursday, August 29, 2013 11:58 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] segmentation fault with 3.8.0

On Thu, Aug 29, 2013 at 11:47 AM, Marc L. Allen <mlal...@outsitenetworks.com
> wrote:

> Silly question.. I looked at the fix.  Why ignore indexes with greater 
> than 4 fields?  Isn't that a bit risky?  Wouldn't it be better to 
> ignore the fields after the 4th one for planning?
>

The whereShortCut() routine is merely an optimization.  It provides a quick 
plan for the common case of a single-table query using an equality constraint 
on a PRIMARY KEY or UNIQUE index.  Anything that falls through
whereShortCut() goes into the regular query planner and will get analyzed 
thoroughly there.

You could omit the whereShortCut() routine entirely and SQLite would still give 
the correct answer.  The only downside is that sqlite3_prepare_v2() would run 
slightly slower in the common case.
--
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


This email and any attachments are only for use by the intended recipient(s) 
and may contain legally privileged, confidential, proprietary or otherwise 
private information. Any unauthorized use, reproduction, dissemination, 
distribution or other disclosure of the contents of this e-mail or its 
attachments is strictly prohibited. If you have received this email in error, 
please notify the sender immediately and delete the original.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread Dan Kennedy

On 08/29/2013 10:47 PM, Marc L. Allen wrote:

Silly question.. I looked at the fix.  Why ignore indexes with greater than 4 
fields?  Isn't that a bit risky?  Wouldn't it be better to ignore the fields 
after the 4th one for planning?


SQLite 3.8.0 really contains two query planners. The first
(in function whereShortcut()) is very fast but only handles
simple cases. The second takes longer to run but handles much
more complicated queries. So, to speed up sqlite3_prepare_v2(),
SQLite tries to use the first planner as much as possible.

The change just has the first planner ignore such indexes. Any
cases that can benefit from using a primary key or unique index
will be handled by the second planner.










-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Richard Hipp
Sent: Thursday, August 29, 2013 11:38 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] segmentation fault with 3.8.0

On Thu, Aug 29, 2013 at 11:32 AM, Stephen Chrzanowski
<pontia...@gmail.com>wrote:


My guess is single quotes instead of double quotes.  Where exactly is
the seg fault?  Untested but other than the quotes, everything looks fine.


The problem is described here: http://www.sqlite.org/src/info/9f2eb3abac

The fix is here: http://www.sqlite.org/src/info/c1152bdcbb

A patch release 3.8.0.1 that includes this fix and fixes for two other equally 
obscure corner cases is currently in test and is expected to go out later today.

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


This email and any attachments are only for use by the intended recipient(s) 
and may contain legally privileged, confidential, proprietary or otherwise 
private information. Any unauthorized use, reproduction, dissemination, 
distribution or other disclosure of the contents of this e-mail or its 
attachments is strictly prohibited. If you have received this email in error, 
please notify the sender immediately and delete the original.
___
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] segmentation fault with 3.8.0

2013-08-29 Thread Richard Hipp
On Thu, Aug 29, 2013 at 11:47 AM, Marc L. Allen  wrote:

> Silly question.. I looked at the fix.  Why ignore indexes with greater
> than 4 fields?  Isn't that a bit risky?  Wouldn't it be better to ignore
> the fields after the 4th one for planning?
>

The whereShortCut() routine is merely an optimization.  It provides a quick
plan for the common case of a single-table query using an equality
constraint on a PRIMARY KEY or UNIQUE index.  Anything that falls through
whereShortCut() goes into the regular query planner and will get analyzed
thoroughly there.

You could omit the whereShortCut() routine entirely and SQLite would still
give the correct answer.  The only downside is that sqlite3_prepare_v2()
would run slightly slower in the common case.
-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread Marc L. Allen
Silly question.. I looked at the fix.  Why ignore indexes with greater than 4 
fields?  Isn't that a bit risky?  Wouldn't it be better to ignore the fields 
after the 4th one for planning? 

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Richard Hipp
Sent: Thursday, August 29, 2013 11:38 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] segmentation fault with 3.8.0

On Thu, Aug 29, 2013 at 11:32 AM, Stephen Chrzanowski
<pontia...@gmail.com>wrote:

> My guess is single quotes instead of double quotes.  Where exactly is 
> the seg fault?  Untested but other than the quotes, everything looks fine.
>

The problem is described here: http://www.sqlite.org/src/info/9f2eb3abac

The fix is here: http://www.sqlite.org/src/info/c1152bdcbb

A patch release 3.8.0.1 that includes this fix and fixes for two other equally 
obscure corner cases is currently in test and is expected to go out later today.

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


This email and any attachments are only for use by the intended recipient(s) 
and may contain legally privileged, confidential, proprietary or otherwise 
private information. Any unauthorized use, reproduction, dissemination, 
distribution or other disclosure of the contents of this e-mail or its 
attachments is strictly prohibited. If you have received this email in error, 
please notify the sender immediately and delete the original.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread Richard Hipp
On Thu, Aug 29, 2013 at 11:38 AM, Richard Hipp  wrote:

>
>
> A patch release 3.8.0.1 that includes this fix and fixes for two other
> equally obscure corner cases is currently in test and is expected to go out
> later today.
>
>
Complete set of diffs for the proposed patch release:
http://www.sqlite.org/src/vdiff?from=f64cd21e2e23ed7c=c5857808c0707baa=1

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


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread Richard Hipp
On Thu, Aug 29, 2013 at 11:32 AM, Stephen Chrzanowski
wrote:

> My guess is single quotes instead of double quotes.  Where exactly is the
> seg fault?  Untested but other than the quotes, everything looks fine.
>

The problem is described here: http://www.sqlite.org/src/info/9f2eb3abac

The fix is here: http://www.sqlite.org/src/info/c1152bdcbb

A patch release 3.8.0.1 that includes this fix and fixes for two other
equally obscure corner cases is currently in test and is expected to go out
later today.

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


Re: [sqlite] segmentation fault with 3.8.0

2013-08-29 Thread Stephen Chrzanowski
My guess is single quotes instead of double quotes.  Where exactly is the
seg fault?  Untested but other than the quotes, everything looks fine.



On Thu, Aug 29, 2013 at 4:07 AM, kenichi ishigaki wrote:

> Hi. I've just got a segmentation fault report with SQLite 3.8.0 from
> one of the perl binding users. The following set of SQL statements
> should reporduce the issue.
>
> Regards,
>
> Kenichi Ishigaki
>
>
>
> CREATE TABLE "twokeys" (
> "artist" integer NOT NULL,
> "cd" integer NOT NULL,
> PRIMARY KEY ("artist", "cd")
> );
>
> CREATE TABLE "fourkeys" (
> "foo" integer NOT NULL,
> "bar" integer NOT NULL,
> "hello" integer NOT NULL,
> "goodbye" integer NOT NULL,
> "sensors" character(10) NOT NULL,
> "read_count" int,
> PRIMARY KEY ("foo", "bar", "hello", "goodbye")
> );
>
> CREATE TABLE "fourkeys_to_twokeys" (
> "f_foo" integer NOT NULL,
> "f_bar" integer NOT NULL,
> "f_hello" integer NOT NULL,
> "f_goodbye" integer NOT NULL,
> "t_artist" integer NOT NULL,
> "t_cd" integer NOT NULL,
> "autopilot" character NOT NULL,
> "pilot_sequence" integer,
> PRIMARY KEY ("f_foo", "f_bar", "f_hello", "f_goodbye", "t_artist", "t_cd")
> );
>
> INSERT INTO fourkeys ( bar, foo, goodbye, hello, read_count, sensors)
> VALUES ( 1, 1, 1, 1, 1, 1 );
>
> INSERT INTO twokeys ( artist, cd) VALUES ( 1, 1 );
>
> INSERT INTO fourkeys_to_twokeys ( autopilot, f_bar, f_foo, f_goodbye,
> f_hello, pilot_sequence, t_artist, t_cd) VALUES ( 1, 1, 1, 1, 1, 1, 1,
> 1 );
>
> DELETE FROM fourkeys_to_twokeys WHERE f_bar = 1 AND f_foo = 1 AND
> f_goodbye = 1 AND f_hello = 1 AND t_artist = 1 AND t_cd = 1;
> ___
> 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] segmentation fault with 3.8.0

2013-08-29 Thread kenichi ishigaki
Hi. I've just got a segmentation fault report with SQLite 3.8.0 from
one of the perl binding users. The following set of SQL statements
should reporduce the issue.

Regards,

Kenichi Ishigaki



CREATE TABLE "twokeys" (
"artist" integer NOT NULL,
"cd" integer NOT NULL,
PRIMARY KEY ("artist", "cd")
);

CREATE TABLE "fourkeys" (
"foo" integer NOT NULL,
"bar" integer NOT NULL,
"hello" integer NOT NULL,
"goodbye" integer NOT NULL,
"sensors" character(10) NOT NULL,
"read_count" int,
PRIMARY KEY ("foo", "bar", "hello", "goodbye")
);

CREATE TABLE "fourkeys_to_twokeys" (
"f_foo" integer NOT NULL,
"f_bar" integer NOT NULL,
"f_hello" integer NOT NULL,
"f_goodbye" integer NOT NULL,
"t_artist" integer NOT NULL,
"t_cd" integer NOT NULL,
"autopilot" character NOT NULL,
"pilot_sequence" integer,
PRIMARY KEY ("f_foo", "f_bar", "f_hello", "f_goodbye", "t_artist", "t_cd")
);

INSERT INTO fourkeys ( bar, foo, goodbye, hello, read_count, sensors)
VALUES ( 1, 1, 1, 1, 1, 1 );

INSERT INTO twokeys ( artist, cd) VALUES ( 1, 1 );

INSERT INTO fourkeys_to_twokeys ( autopilot, f_bar, f_foo, f_goodbye,
f_hello, pilot_sequence, t_artist, t_cd) VALUES ( 1, 1, 1, 1, 1, 1, 1,
1 );

DELETE FROM fourkeys_to_twokeys WHERE f_bar = 1 AND f_foo = 1 AND
f_goodbye = 1 AND f_hello = 1 AND t_artist = 1 AND t_cd = 1;
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault in SQLite parser

2013-05-01 Thread Richard Hipp
On Wed, May 1, 2013 at 9:27 AM, Klaas V  wrote:

> Eelco wrote:
> Using version 3.7.16.2
> select * from ((select * from x)) y;
> Segmentation fault
>
>
> On OSX we get 'Bus error'.


Thanks for the report.  This bug has already been fixed.  See
http://www.sqlite.org/src/info/28c6e830f2 for the ticket and
http://www.sqlite.org/src/info/1c79569226 for the patch.



> Not a bug, because you were syntactical not exact enough.
> See http://www.sqlite.org/lang_select.html
>
> You're supposed to use only one pair () not more. Before 3.7.15 or 16 the
> extra pair were user friendly ignored.
>
> Following example from an ancient version where you see that existence of
> a table makes a difference:
>
> SQLite version 3.6.12
> Enter ".help" for instructions
> Enter SQL statements terminated with a ";"
> sqlite> create table dual (dummy);
> sqlite> insert into dual values (1);
> sqlite> .schema
> CREATE TABLE dual (dummy);
> sqlite> select * from dual;
> 1
> sqlite>  select * from ((select * from x)) y;
> SQL error: no such table: x
> sqlite> select * from ((select * from dual)) bar;
> 1
> sqlite> select * from (select * from dual) bar;
> 1
>
> An example where newer versions ask more attention to developers.
>
> Cordiali saluti/Vriendelijke groeten/Kind regards,
> Klaas "Z4us" V MetaDBA
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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


Re: [sqlite] Segmentation fault in SQLite parser

2013-05-01 Thread Klaas V
Eelco wrote: 
Using version 3.7.16.2
select * from ((select * from x)) y;
Segmentation fault


On OSX we get 'Bus error'. Not a bug, because you were syntactical not exact 
enough.
See http://www.sqlite.org/lang_select.html 

You're supposed to use only one pair () not more. Before 3.7.15 or 16 the extra 
pair were user friendly ignored.

Following example from an ancient version where you see that existence of a 
table makes a difference:

SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table dual (dummy);
sqlite> insert into dual values (1);
sqlite> .schema
CREATE TABLE dual (dummy);
sqlite> select * from dual;
1
sqlite>  select * from ((select * from x)) y;
SQL error: no such table: x
sqlite> select * from ((select * from dual)) bar;
1
sqlite> select * from (select * from dual) bar;
1

An example where newer versions ask more attention to developers. 

Cordiali saluti/Vriendelijke groeten/Kind regards,
Klaas "Z4us" V MetaDBA
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Segmentation fault in SQLite parser

2013-04-30 Thread Eelco Dolstra
Hi,

I ran into the following regression after upgrading from SQLite 3.7.14.1 to
3.7.16.2: the SQLite parser crashes when it encounters a subquery enclosed in
double parentheses.

For example:

$ sqlite3
SQLite version 3.7.16.2 2013-04-12 11:52:43
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from ((select * from x)) y;
Segmentation fault

(It doesn't matter whether table "x" exists or not.)  On SQLite 3.7.14.1, this
worked correctly.  The problem can be fixed by removing the redundant
parentheses, but the parser shouldn't segfault when encountering this.

The stack trace is as follows:

> #0  0x77b7b0b3 in selectExpander (pWalker=0x7fffb4a0, p=0x620278) 
> at sqlite3.c:98052
> #1  0x77b4f69b in sqlite3WalkSelect (pWalker=0x7fffb4a0, 
> p=0x620278) at sqlite3.c:72631
> #2  0x77b7baf1 in sqlite3SelectExpand (pParse=0x620808, 
> pSelect=0x620278) at sqlite3.c:98298
> #3  0x77b7bc8d in sqlite3SelectPrep (pParse=0x620808, p=0x620278, 
> pOuterNC=0x0) at sqlite3.c:98383
> #4  0x77b7c44a in sqlite3Select (pParse=0x620808, p=0x620278, 
> pDest=0x7fffb7f0) at sqlite3.c:98648
> #5  0x77b8f719 in yy_reduce (yypParser=0x620ab8, yyruleno=112) at 
> sqlite3.c:111032
> #6  0x77b926b2 in sqlite3Parser (yyp=0x620ab8, yymajor=1, 
> yyminor=..., pParse=0x620808) at sqlite3.c:112034
> #7  0x77b933ef in sqlite3RunParser (pParse=0x620808, zSql=0x60f530 
> "select * from ((select * from x)) y;", pzErrMsg=0x7fffbaa0) at 
> sqlite3.c:112859
> #8  0x77b74436 in sqlite3Prepare (db=0x60f568, zSql=0x60f530 "select 
> * from ((select * from x)) y;", nBytes=-1, saveSqlFlag=1, pReprepare=0x0, 
> ppStmt=0x7fffbc08, 
> pzTail=0x7fffbc00) at sqlite3.c:94461
> #9  0x77b74772 in sqlite3LockAndPrepare (db=0x60f568, zSql=0x60f530 
> "select * from ((select * from x)) y;", nBytes=-1, saveSqlFlag=1, pOld=0x0, 
> ppStmt=0x7fffbc08, 
> pzTail=0x7fffbc00) at sqlite3.c:94553
> #10 0x77b74929 in sqlite3_prepare_v2 (db=0x60f568, zSql=0x60f530 
> "select * from ((select * from x)) y;", nBytes=-1, ppStmt=0x7fffbc08, 
> pzTail=0x7fffbc00) at sqlite3.c:94629
> #11 0x00404b51 in shell_exec (db=0x60f568, zSql=0x60f530 "select * 
> from ((select * from x)) y;", xCallback=0x403038 , 
> pArg=0x7fffbd40, pzErrMsg=0x7fffbce8)
> at shell.c:1144
> #12 0x00409dd9 in process_input (p=0x7fffbd40, in=0x0) at 
> shell.c:2728
> #13 0x0040b06b in main (argc=1, argv=0x7fffd3d8) at shell.c:3189

This is on NixOS Linux, 64-bit, GCC 4.6.3 and Glibc 2.17. Also confirmed with
the 2013-04-26 SQLite snapshot.

-- 
Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault when calling sqlite3_finalize

2012-05-31 Thread Stephen Wood
That is actually how I originally wrote the function, but when I started
having the segmentation faults I thought maybe I was mistaken on that count
and rewrote it with the call to the step function. Thanks for the tip!

On Thu, May 31, 2012 at 11:31 AM, Dan Kennedy  wrote:

> On 05/31/2012 10:46 PM, Stephen Wood wrote:
>
>> Hello all,
>> I'm having some memory allocation difficulties while using the SQLite C
>> API. The goal of the function that is currently giving me issues is just
>> trying to read the column names from a table.
>>
>
> Tip: Column names are available after sqlite3_prepare_v2() has
> returned. You don't need the sqlite3_step() call in your function.
>
>
> __**_
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-**bin/mailman/listinfo/sqlite-**users
>



-- 
Stephen Wood
RMCI, INC.
1525 Perimeter Parkway
Suite 430
Huntsville, AL  35806**
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault when calling sqlite3_finalize

2012-05-31 Thread Dan Kennedy

On 05/31/2012 10:46 PM, Stephen Wood wrote:

Hello all,
I'm having some memory allocation difficulties while using the SQLite C
API. The goal of the function that is currently giving me issues is just
trying to read the column names from a table.


Tip: Column names are available after sqlite3_prepare_v2() has
returned. You don't need the sqlite3_step() call in your function.

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


Re: [sqlite] Segmentation Fault when calling sqlite3_finalize

2012-05-31 Thread Stephen Wood
Thank you! I can't believe I missed that!

On Thu, May 31, 2012 at 10:50 AM, Marc L. Allen <mlal...@outsitenetworks.com
> wrote:

>columnNames[i] = malloc(strlen(buffer) + 1);
>
> Need to deal with that pesky '\0'!
>
> -Original Message-
> From: sqlite-users-boun...@sqlite.org [mailto:
> sqlite-users-boun...@sqlite.org] On Behalf Of Stephen Wood
> Sent: Thursday, May 31, 2012 11:47 AM
> To: sqlite-users@sqlite.org
> Subject: [sqlite] Segmentation Fault when calling sqlite3_finalize
>
> Hello all,
> I'm having some memory allocation difficulties while using the SQLite C
> API. The goal of the function that is currently giving me issues is just
> trying to read the column names from a table. I have been having other
> memory allocation faults elsewhere, but I currently have it isolated to
> this particular section of code (I say this because I suppose the root
> problem could be elsewhere in my code). Also strangely enough, if I do not
> store the data returned from sqlite3_column_name, but instead just print it
> to stdout, I do not get a segmentation fault, which also leads to me
> thinking my error may be more fundamental... This function is also run
> multiple times and only produces segmentation faults on the third table I
> run it on. I am using the database here<
> http://download.codeplex.com/Download/Release?ProjectName=chinookdatabase=167067=12934269926367=18924
> >for
> testing.
>
> Please let me know if I can provide any more relevant information.
>
> Any help would be greatly appreciated. Below is the relevant code segment.
> Thanks!
>
> char **getColumnNames(char **columnNames, sqlite3 *database, char
> *tableName) {
>sqlite3_stmt *statement = NULL;
>char sqlStatementString[100];
>char *sqlErrorMessage = 0;
>char buffer[100];
>int status = 0;
>int i = 0;
>int numOfCols = 0;
>
>// Prepare a statement to get the tables from the database
> sprintf(sqlStatementString, "SELECT * FROM '%s';", tableName);
>status = sqlite3_prepare_v2(database, sqlStatementString,
> strlen(sqlStatementString), , NULL);
>if (status != SQLITE_OK) {
>fprintf(stderr, "Error occured when attempting to prepare an SQL
> statement\n"
>"Error:%s\n", sqlErrorMessage);
>// Prevents memory leaking from error message:
>sqlite3_free(sqlErrorMessage);
>exit(1);
>} // end error check
>
>// I only want the first row, because I am only getting the names
>// for the columns. This is why I only run the step function once
>if (sqlite3_step(statement) != SQLITE_ROW) {
>fprintf(stderr, "Either an error occured or table \"%s\" has no
> data!\n", tableName);
>exit(1);
>}
>
>numOfCols = sqlite3_column_count(statement);
>if (numOfCols < 1) {
>perror("No columns in that table!\n");
>exit(1);
>}
>
>columnNames = (char **) malloc(numOfCols * sizeof(char *));
>if (columnNames == NULL) {
>perror("Allocation error: ");
>exit(1);
>} // end error check for malloc
>
>for (i = 0; i < numOfCols; i++) {
>sprintf(buffer,  "%s", (char *) sqlite3_column_name(statement, i));
>
>columnNames[i] = malloc(strlen(buffer));
>if (columnNames[i] == NULL) {
>perror("Failed to allocate memory for a column name\n");
>exit(1);
>} // end malloc error check
>
>strcpy(columnNames[i], buffer);
>} // end column loop
>
>// Destroy the statement
>//  THIS IS WHERE I GET THE SEGMENTATION FAULT **
>status = sqlite3_finalize(statement);
>if (status != SQLITE_OK) {
>fprintf(stderr, "Error occured when attempting to destroy a SQL
> statement\n"
>"Error:%s\n", sqlErrorMessage);
>// Prevents memory leaking from error message:
>sqlite3_free(sqlErrorMessage);
>exit(1);
>} // end error check
>
>return columnNames;
>} // end of function
>
>
> --
> Stephen Wood
> RMCI, INC.
> 1525 Perimeter Parkway
> Suite 430
> Huntsville, AL  35806**
> **
> ___
> 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
>



-- 
Stephen Wood
RMCI, INC.
1525 Perimeter Parkway
Suite 430
Huntsville, AL  35806**
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation Fault when calling sqlite3_finalize

2012-05-31 Thread Marc L. Allen
columnNames[i] = malloc(strlen(buffer) + 1);

Need to deal with that pesky '\0'!

-Original Message-
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Stephen Wood
Sent: Thursday, May 31, 2012 11:47 AM
To: sqlite-users@sqlite.org
Subject: [sqlite] Segmentation Fault when calling sqlite3_finalize

Hello all,
I'm having some memory allocation difficulties while using the SQLite C API. 
The goal of the function that is currently giving me issues is just trying to 
read the column names from a table. I have been having other memory allocation 
faults elsewhere, but I currently have it isolated to this particular section 
of code (I say this because I suppose the root problem could be elsewhere in my 
code). Also strangely enough, if I do not store the data returned from 
sqlite3_column_name, but instead just print it to stdout, I do not get a 
segmentation fault, which also leads to me thinking my error may be more 
fundamental... This function is also run multiple times and only produces 
segmentation faults on the third table I run it on. I am using the database 
here<http://download.codeplex.com/Download/Release?ProjectName=chinookdatabase=167067=12934269926367=18924>for
testing.

Please let me know if I can provide any more relevant information.

Any help would be greatly appreciated. Below is the relevant code segment.
Thanks!

char **getColumnNames(char **columnNames, sqlite3 *database, char
*tableName) {
sqlite3_stmt *statement = NULL;
char sqlStatementString[100];
char *sqlErrorMessage = 0;
char buffer[100];
int status = 0;
int i = 0;
int numOfCols = 0;

// Prepare a statement to get the tables from the database 
sprintf(sqlStatementString, "SELECT * FROM '%s';", tableName);
status = sqlite3_prepare_v2(database, sqlStatementString, 
strlen(sqlStatementString), , NULL);
if (status != SQLITE_OK) {
fprintf(stderr, "Error occured when attempting to prepare an SQL 
statement\n"
"Error:%s\n", sqlErrorMessage);
// Prevents memory leaking from error message:
sqlite3_free(sqlErrorMessage);
exit(1);
} // end error check

// I only want the first row, because I am only getting the names
// for the columns. This is why I only run the step function once
if (sqlite3_step(statement) != SQLITE_ROW) {
fprintf(stderr, "Either an error occured or table \"%s\" has no 
data!\n", tableName);
exit(1);
}

numOfCols = sqlite3_column_count(statement);
if (numOfCols < 1) {
perror("No columns in that table!\n");
exit(1);
}

columnNames = (char **) malloc(numOfCols * sizeof(char *));
if (columnNames == NULL) {
perror("Allocation error: ");
exit(1);
} // end error check for malloc

for (i = 0; i < numOfCols; i++) {
sprintf(buffer,  "%s", (char *) sqlite3_column_name(statement, i));

columnNames[i] = malloc(strlen(buffer));
if (columnNames[i] == NULL) {
perror("Failed to allocate memory for a column name\n");
exit(1);
} // end malloc error check

strcpy(columnNames[i], buffer);
} // end column loop

// Destroy the statement
//  THIS IS WHERE I GET THE SEGMENTATION FAULT **
status = sqlite3_finalize(statement);
if (status != SQLITE_OK) {
fprintf(stderr, "Error occured when attempting to destroy a SQL 
statement\n"
"Error:%s\n", sqlErrorMessage);
// Prevents memory leaking from error message:
sqlite3_free(sqlErrorMessage);
exit(1);
} // end error check

return columnNames;
} // end of function


--
Stephen Wood
RMCI, INC.
1525 Perimeter Parkway
Suite 430
Huntsville, AL  35806**
**
___
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] Segmentation Fault when calling sqlite3_finalize

2012-05-31 Thread Stephen Wood
Hello all,
I'm having some memory allocation difficulties while using the SQLite C
API. The goal of the function that is currently giving me issues is just
trying to read the column names from a table. I have been having other
memory allocation faults elsewhere, but I currently have it isolated to
this particular section of code (I say this because I suppose the root
problem could be elsewhere in my code). Also strangely enough, if I do not
store the data returned from sqlite3_column_name, but instead just print it
to stdout, I do not get a segmentation fault, which also leads to me
thinking my error may be more fundamental... This function is also run
multiple times and only produces segmentation faults on the third table I
run it on. I am using the database
herefor
testing.

Please let me know if I can provide any more relevant information.

Any help would be greatly appreciated. Below is the relevant code segment.
Thanks!

char **getColumnNames(char **columnNames, sqlite3 *database, char
*tableName) {
sqlite3_stmt *statement = NULL;
char sqlStatementString[100];
char *sqlErrorMessage = 0;
char buffer[100];
int status = 0;
int i = 0;
int numOfCols = 0;

// Prepare a statement to get the tables from the database
sprintf(sqlStatementString, "SELECT * FROM '%s';", tableName);
status = sqlite3_prepare_v2(database, sqlStatementString,
strlen(sqlStatementString), , NULL);
if (status != SQLITE_OK) {
fprintf(stderr, "Error occured when attempting to prepare an SQL
statement\n"
"Error:%s\n", sqlErrorMessage);
// Prevents memory leaking from error message:
sqlite3_free(sqlErrorMessage);
exit(1);
} // end error check

// I only want the first row, because I am only getting the names
// for the columns. This is why I only run the step function once
if (sqlite3_step(statement) != SQLITE_ROW) {
fprintf(stderr, "Either an error occured or table \"%s\" has no
data!\n", tableName);
exit(1);
}

numOfCols = sqlite3_column_count(statement);
if (numOfCols < 1) {
perror("No columns in that table!\n");
exit(1);
}

columnNames = (char **) malloc(numOfCols * sizeof(char *));
if (columnNames == NULL) {
perror("Allocation error: ");
exit(1);
} // end error check for malloc

for (i = 0; i < numOfCols; i++) {
sprintf(buffer,  "%s", (char *) sqlite3_column_name(statement, i));

columnNames[i] = malloc(strlen(buffer));
if (columnNames[i] == NULL) {
perror("Failed to allocate memory for a column name\n");
exit(1);
} // end malloc error check

strcpy(columnNames[i], buffer);
} // end column loop

// Destroy the statement
//  THIS IS WHERE I GET THE SEGMENTATION FAULT **
status = sqlite3_finalize(statement);
if (status != SQLITE_OK) {
fprintf(stderr, "Error occured when attempting to destroy a SQL
statement\n"
"Error:%s\n", sqlErrorMessage);
// Prevents memory leaking from error message:
sqlite3_free(sqlErrorMessage);
exit(1);
} // end error check

return columnNames;
} // end of function


-- 
Stephen Wood
RMCI, INC.
1525 Perimeter Parkway
Suite 430
Huntsville, AL  35806**
**
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-05 Thread Marcus Grimm
>> > change this code:
>> >  typedef struct NiuRoutingStruct {
>> >  sqlite3_vtab vtab;
>> >  } NiuRouting;
>> > to this:
>> >  struct NiuRouting : public sqlite3_vtab vtab {
>> >   ... // your implementation, eventually
>> >  };
>> >
>> > This way, the casting is unnecessary and any pointer offsetting will
>> be
>> > done correctly.
>>
>> Just for my curiosity:
>> Is the above really equivalent to the C definition like:
>> typedef struct NiuRoutingStruct {
>>sqlite3_vtab vtab;
>> ... // your implementation, eventually
>> } NiuRouting;
>>
>> ?
>>
>> Reason I'm asking: sqlite uses a pointer to that structure to access
>> "sqlite3_vtab vtab" member - in machine code that would be
>> memory offset 0, all other private members start at
>> +sizeof(sqlite3_vtab)+optional alignment.
>> Now, I'm wondering if a c++ style of inheritance is defined
>> in the same way - Note that sqlite relies on that, or better
>> say "the compiler that produced the sqlite machine code relies
>> on that".
>> Just in case the c++ compiler rearrange the byte offset differently
>> it will crash rights away, I think.
>>
>> Thanks.
>
> Without my copy/paste error, (the 'vtab' should be gone, leaving just the
> struct name), it would be equivalent provided that the alignment of a
> sqlite3_vtab was no less restrictive than the alignment of
> NiuRoutingStruct as it is finally defined.  However, static_casting from
> derived to base automatically incorporates the correct offset, (as would
> taking the address of an embedded sqlite3_vtab member, instead of using
> the OP's reinterpret cast), so the crash you worry about (with good
> reason) would  be made less likely.

okay, thank you for the explanation. Interesting subject.

Kind regards

Marcus

>
> I think all SQLite relies upon is getting correct pointers to its portion
> of whatever object it is passing around.  That virtual table API is
> designed to make it agnostic as to any other, tag-along content.
>
> Best regards,
> --
> Larry Brasfield
>
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-04 Thread larry_brasfield
> > change this code:
> >  typedef struct NiuRoutingStruct {
> >  sqlite3_vtab vtab;
> >  } NiuRouting;
> > to this:
> >  struct NiuRouting : public sqlite3_vtab vtab {
> >   ... // your implementation, eventually
> >  };
> >
> > This way, the casting is unnecessary and any pointer offsetting will be
> > done correctly.
>
> Just for my curiosity:
> Is the above really equivalent to the C definition like:
> typedef struct NiuRoutingStruct {
>sqlite3_vtab vtab;
> ... // your implementation, eventually
> } NiuRouting;
>
> ?
>
> Reason I'm asking: sqlite uses a pointer to that structure to access
> "sqlite3_vtab vtab" member - in machine code that would be
> memory offset 0, all other private members start at
> +sizeof(sqlite3_vtab)+optional alignment.
> Now, I'm wondering if a c++ style of inheritance is defined
> in the same way - Note that sqlite relies on that, or better
> say "the compiler that produced the sqlite machine code relies
> on that".
> Just in case the c++ compiler rearrange the byte offset differently
> it will crash rights away, I think.
>
> Thanks.

Without my copy/paste error, (the 'vtab' should be gone, leaving just the
struct name), it would be equivalent provided that the alignment of a
sqlite3_vtab was no less restrictive than the alignment of
NiuRoutingStruct as it is finally defined.  However, static_casting from
derived to base automatically incorporates the correct offset, (as would
taking the address of an embedded sqlite3_vtab member, instead of using
the OP's reinterpret cast), so the crash you worry about (with good
reason) would  be made less likely.

I think all SQLite relies upon is getting correct pointers to its portion
of whatever object it is passing around.  That virtual table API is
designed to make it agnostic as to any other, tag-along content.

Best regards,
-- 
Larry Brasfield

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


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Marcus Grimm
> Stephan Beal wrote:
>> 2012/2/3 Jorge Eliécer Osorio Caro 
>>
>> >*ppVTab = (sqlite3_vtab*) nr;
>> > ((sqlite3_vtab*) nr)->zErrMsg = NULL;
>> >
>>
>> Please try changing those to the variants from my previous post. i'm not
>> 100% convinced that that cast is strictly legal in C++.
>
> It will work with all the C/C++ implementations I've seen.  However, it
> would be better, and more informative, and ultimately more robust, to
> change this code:
>  typedef struct NiuRoutingStruct {
>  sqlite3_vtab vtab;
>  } NiuRouting;
> to this:
>  struct NiuRouting : public sqlite3_vtab vtab {
>   ... // your implementation, eventually
>  };
>
> This way, the casting is unnecessary and any pointer offsetting will be
> done correctly.

Just for my curiosity:
Is the above really equivalent to the C definition like:
typedef struct NiuRoutingStruct {
   sqlite3_vtab vtab;
... // your implementation, eventually
} NiuRouting;

?

Reason I'm asking: sqlite uses a pointer to that structure to access
"sqlite3_vtab vtab" member - in machine code that would be
memory offset 0, all other private members start at
+sizeof(sqlite3_vtab)+optional alignment.
Now, I'm wondering if a c++ style of inheritance is defined
in the same way - Note that sqlite relies on that, or better
say "the compiler that produced the sqlite machine code relies
on that".
Just in case the c++ compiler rearrange the byte offset differently
it will crash rights away, I think.

Thanks.

Marcus


>
> The use of C-style casts in C++ is bad practice.  Use static_cast where
> you can.  The problem with C-style casting is that it can become a
> reinterpret_cast when that is going to produce problems.
>
> --
> Larry Brasfield
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Larry Brasfield

Stephan Beal wrote:

2012/2/3 Jorge Eliécer Osorio Caro 

>*ppVTab = (sqlite3_vtab*) nr;
> ((sqlite3_vtab*) nr)->zErrMsg = NULL;
>

Please try changing those to the variants from my previous post. i'm not
100% convinced that that cast is strictly legal in C++.


It will work with all the C/C++ implementations I've seen.  However, it 
would be better, and more informative, and ultimately more robust, to 
change this code:

typedef struct NiuRoutingStruct {
sqlite3_vtab vtab;
} NiuRouting;
to this:
struct NiuRouting : public sqlite3_vtab vtab {
 ... // your implementation, eventually
};

This way, the casting is unnecessary and any pointer offsetting will be 
done correctly.


The use of C-style casts in C++ is bad practice.  Use static_cast where 
you can.  The problem with C-style casting is that it can become a 
reinterpret_cast when that is going to produce problems.


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


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Larry Brasfield

Marcus wrote:

>> So, you might have a calling convencion issue...
>>
>> Just a guess, though.
>
> The sqlite3.h header has proper, "extern "C" {" wrappers around its
> declarations, guarded by "#ifdef __cplusplus", so this is not an issue.
>   It is perfectly reasonable to call into the SQLite code from C++.

Right, you can call sqlite from c++ - no problem.
But here we define function pointers (compiled as c++),
provide them via sqlite3_module structure to a c library.
That is why I was guessing that it might not be clear for the
c-library that the function pointer is compiled within a
c++ frame.


Yes, that's a good point.  (To the O.P.:) It would be a good idea to 
wrap the same 'extern "C" { }' around forward declarations for your 
functions that are going into that v-table (as pointers), and be sure 
that they are seen during compilation of those functions.


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


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Marcus Grimm
> Marcus wrote:
>> Just a guess:
>> It looks you are compiling/using c++, on Windows that wouldn't work
>> if the sqlite library is compiled as C (which is the usual case).
>>
>> So, you might have a calling convencion issue...
>>
>> Just a guess, though.
>
> The sqlite3.h header has proper, "extern "C" {" wrappers around its
> declarations, guarded by "#ifdef __cplusplus", so this is not an issue.
>   It is perfectly reasonable to call into the SQLite code from C++.

Right, you can call sqlite from c++ - no problem.
But here we define function pointers (compiled as c++),
provide them via sqlite3_module structure to a c library.
That is why I was guessing that it might not be clear for the
c-library that the function pointer is compiled within a
c++ frame.

Again, just guessing...

Marcus

>
> --
> Larry Brasfield
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Larry Brasfield

Marcus wrote:

Just a guess:
It looks you are compiling/using c++, on Windows that wouldn't work
if the sqlite library is compiled as C (which is the usual case).

So, you might have a calling convencion issue...

Just a guess, though.


The sqlite3.h header has proper, "extern "C" {" wrappers around its 
declarations, guarded by "#ifdef __cplusplus", so this is not an issue. 
 It is perfectly reasonable to call into the SQLite code from C++.


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


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Marcus Grimm
> Hi,
>
> I do this:
>
> const char *table_structure = "CREATE TABLE network (vertex_id INTEGER);";
> if (sqlite3_declare_vtab(db, table_structure) == SQLITE_OK) {
> nr = (NiuRouting*) sqlite3_malloc(sizeof (NiuRouting));
>
> if (nr == NULL) {
> //*pzErr = sqlite3_mprintf("[NiuRouting module] CREATE
> VIRTUAL: No memory \n");
> return SQLITE_NOMEM;
> }
>
> *ppVTab = (sqlite3_vtab*) nr;
> ((sqlite3_vtab*) nr)->zErrMsg = NULL;
>
> } else {
> //*pzErr = sqlite3_mprintf("[NiuRouting module] CREATE
> VIRTUAL:
> invalid SQL statement \n");
> return SQLITE_ERROR;
> }
>
> and continue.
>
> i do somethig more comment all the code inside the functions and get the
> same error. when try to load extension i just see the first debug message
> i
> can see any more i think, that the program do no enter to any method.

Just a guess:
It looks you are compiling/using c++, on Windows that wouldn't work
if the sqlite library is compiled as C (which is the usual case).

So, you might have a calling convencion issue...

Just a guess, though.

Marcus


>
> 2012/2/3 Stephan Beal 
>
>> 2012/2/3 Jorge Eliécer Osorio Caro 
>>
>> > Yes, that's my code:
>> >
>> > http://paste.ideaslabs.com/show/OPNHBY7xPG
>> >
>> > this the backtrace:
>> >
>> > #0  0x0001001701d3 in initialize_niurouting ()
>> >
>>
>> Can you try the following (but i'm just guessing here);
>>
>> std::cerr << "virtual_table_name="<>  << ", network_structure_table="
>>  <>
>> after those vars are initialized, and change:
>>
>> std::string table_structure(...)
>>
>> to
>> const static std::string table_structure(...)
>>
>> sqlite3_declare_vtab()[1] does not document the lifetime requirements of
>> the string passed to it, and it's "conceivable" that the lifetime of the
>> table_structure string is the problem.
>>
>> :-?
>>
>> [1] = http://www.sqlite.org/c3ref/declare_vtab.html
>>
>> --
>> - stephan beal
>> http://wanderinghorse.net/home/stephan/
>> http://gplus.to/sgbeal
>> ___
>> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
2012/2/3 Jorge Eliécer Osorio Caro 

>*ppVTab = (sqlite3_vtab*) nr;
> ((sqlite3_vtab*) nr)->zErrMsg = NULL;
>

Please try changing those to the variants from my previous post. i'm not
100% convinced that that cast is strictly legal in C++.

>can see any more i think, that the program do no enter to any >method.

And please show us what the DBG macro expands to - maybe the problem is in
the first DBG() call?


-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Jorge Eliécer Osorio Caro
Hi,

I do this:

const char *table_structure = "CREATE TABLE network (vertex_id INTEGER);";
if (sqlite3_declare_vtab(db, table_structure) == SQLITE_OK) {
nr = (NiuRouting*) sqlite3_malloc(sizeof (NiuRouting));

if (nr == NULL) {
//*pzErr = sqlite3_mprintf("[NiuRouting module] CREATE
VIRTUAL: No memory \n");
return SQLITE_NOMEM;
}

*ppVTab = (sqlite3_vtab*) nr;
((sqlite3_vtab*) nr)->zErrMsg = NULL;

} else {
//*pzErr = sqlite3_mprintf("[NiuRouting module] CREATE VIRTUAL:
invalid SQL statement \n");
return SQLITE_ERROR;
}

and continue.

i do somethig more comment all the code inside the functions and get the
same error. when try to load extension i just see the first debug message i
can see any more i think, that the program do no enter to any method.

2012/2/3 Stephan Beal 

> 2012/2/3 Jorge Eliécer Osorio Caro 
>
> > Yes, that's my code:
> >
> > http://paste.ideaslabs.com/show/OPNHBY7xPG
> >
> > this the backtrace:
> >
> > #0  0x0001001701d3 in initialize_niurouting ()
> >
>
> Can you try the following (but i'm just guessing here);
>
> std::cerr << "virtual_table_name="<  << ", network_structure_table="
>  <
> after those vars are initialized, and change:
>
> std::string table_structure(...)
>
> to
> const static std::string table_structure(...)
>
> sqlite3_declare_vtab()[1] does not document the lifetime requirements of
> the string passed to it, and it's "conceivable" that the lifetime of the
> table_structure string is the problem.
>
> :-?
>
> [1] = http://www.sqlite.org/c3ref/declare_vtab.html
>
> --
> - stephan beal
> http://wanderinghorse.net/home/stephan/
> http://gplus.to/sgbeal
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
On Fri, Feb 3, 2012 at 8:25 PM, Stephan Beal  wrote:

> i take that back - if that were the case then the crash would almost
> certainly happen later on (after your init routine returns). But it still
> can't hurt to try.
>

But please try this:

nr = (NiuRouting*) sqlite3_malloc(sizeof (NiuRouting));
...
*ppVTab = (sqlite3_vtab*) nr;

i'm not sure (i don't remember) if such a cast to the first type in a
struct is legal in C++ (it is in C). Try changing the 2nd line to:

*ppVTab = >vtab;

And change:
((sqlite3_vtab*) nr)->zErrMsg = NULL;

to:
nr->vtab.zErrMsg = NULL;

The casts aren't necessary (this is C++!) and hurt the readability.

Note that nr is NOT initialized in your code (it is allocated, but not set
up). Does it need to be? (i'm not familiar with the vtable's requirements -
maybe it only needs to be allocated.)

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
On Fri, Feb 3, 2012 at 8:22 PM, Stephan Beal  wrote:

> sqlite3_declare_vtab()[1] does not document the lifetime requirements of
> the string passed to it, and it's "conceivable" that the lifetime of the
> table_structure string is the problem.
>

i take that back - if that were the case then the crash would almost
certainly happen later on (after your init routine returns). But it still
can't hurt to try.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
2012/2/3 Jorge Eliécer Osorio Caro 

> Yes, that's my code:
>
> http://paste.ideaslabs.com/show/OPNHBY7xPG
>
> this the backtrace:
>
> #0  0x0001001701d3 in initialize_niurouting ()
>

Can you try the following (but i'm just guessing here);

std::cerr << "virtual_table_name="

Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Jorge Eliécer Osorio Caro
Yes, that's my code:

http://paste.ideaslabs.com/show/OPNHBY7xPG

this the backtrace:

#0  0x0001001701d3 in initialize_niurouting ()
#1  0x0001001709d5 in sqlite3_extension_init ()
#2  0x0001000499a3 in sqlite3_load_extension (db=0x100200090,
zFile=0x10020f206
"/Volumes/Me/jorge.osorio/proj/niurouting/bin/niurouting.sqlext",
zProc=0x1000a1480 "sqlite3_extension_init", pzErrMsg=0x7fff5fbfd778) at
sqlite3.c:91718
#3  0x000155db in do_meta_command (zLine=, p=0x7fff5fbfe2e0) at ./src/shell.c:1885
#4  0x000140da in process_input (p=0x7fff5fbfe2e0, in=0x0) at
./src/shell.c:2481
#5  0x000171c8 in main (argc=2, argv=) at ./src/shell.c:2972
(gdb)

it's strange Stepan, thanks for you help..

2012/2/3 Stephan Beal 

> 2012/2/3 Jorge Eliécer Osorio Caro 
>
> > OK there is the trace:
> >
> > Program received signal EXC_BAD_ACCESS, Could not access memory.
> > Reason: KERN_INVALID_ADDRESS at address: 0x03b8
> > 0x00010017024b in initialize_niurouting ()
> >
>
> That's the reason for the crash but not the backtrace, so i can't say what
> let up to the crash, but the "Reason" part is telling - the address 03b8 is
> invalid. Are you sure you've properly initialized all of the
> memory/variables in initialize_niurouting()?
>
> --
> - stephan beal
> http://wanderinghorse.net/home/stephan/
> http://gplus.to/sgbeal
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
2012/2/3 Jorge Eliécer Osorio Caro 

> OK there is the trace:
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_INVALID_ADDRESS at address: 0x03b8
> 0x00010017024b in initialize_niurouting ()
>

That's the reason for the crash but not the backtrace, so i can't say what
let up to the crash, but the "Reason" part is telling - the address 03b8 is
invalid. Are you sure you've properly initialized all of the
memory/variables in initialize_niurouting()?

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Jorge Eliécer Osorio Caro
OK there is the trace:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x03b8
0x00010017024b in initialize_niurouting ()

2012/2/3 Stephan Beal 

> 2012/2/3 Jorge Eliécer Osorio Caro 
>
> > Ok, tthanks Stepha, how i can do that? i compile sqlite like ./configure
> > --enable-debug but i cant do a trace to see what happend
> >
>
> Assuming you're on a Linux (or similar) platform you can try:
>
> gdb --args sqlite3 dbfile
>
> then run it as normal until it crashes, then type "bt" to get a backtrace.
> That will show what led up to the error.
>
> --
> - stephan beal
> http://wanderinghorse.net/home/stephan/
> http://gplus.to/sgbeal
> ___
> 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
2012/2/3 Jorge Eliécer Osorio Caro 

> Ok, tthanks Stepha, how i can do that? i compile sqlite like ./configure
> --enable-debug but i cant do a trace to see what happend
>

Assuming you're on a Linux (or similar) platform you can try:

gdb --args sqlite3 dbfile

then run it as normal until it crashes, then type "bt" to get a backtrace.
That will show what led up to the error.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Jorge Eliécer Osorio Caro
Ok, tthanks Stepha, how i can do that? i compile sqlite like ./configure
--enable-debug but i cant do a trace to see what happend

2012/2/3 Stephan Beal 

> But finding out exactly where it fails requires either adding debug output
> to the plug or running it (in this case the sqlite shell) through a
> debugger.
>
> - stephan beal
> http://wanderinghorse.net/home/stephan/
> http://gplus.to/sgbeal
> On Feb 3, 2012 4:35 PM, "Jorge Eliécer Osorio Caro" <
> jorgeliecer.oso...@gmail.com> wrote:
>
> > It's caused calling a sqlite_create_module trying to load an extension by
> > sqlite3 shell.
> >
> > 2012/2/3 Stephan Beal 
> >
> > > 2012/2/3 Jorge Eliécer Osorio Caro 
> > >
> > > > Good morning every one,
> > > >
> > > > I having a issue when try to create a sqlite3_create_module.
> > > >
> > > > when try to load my extension im getting that error "Segmentation
> > fault",
> > > > cause the sqlite3 cash. i dont know how it happend its my code:
> > > >
> > > > http://paste.ideaslabs.com/show/OPNHBY7xPG
> > >
> > >
> > > A segfault can be caused by at least 300 million different things. The
> > > easiest way to figure out where the problem is is to run your app
> through
> > > gdb (or equivalent) and get a backtrace after it crashes.
> > >
> > > --
> > > - stephan beal
> > > http://wanderinghorse.net/home/stephan/
> > > http://gplus.to/sgbeal
> > > ___
> > > 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] Segmentation fault on sqlite3_create_module

2012-02-03 Thread Stephan Beal
But finding out exactly where it fails requires either adding debug output
to the plug or running it (in this case the sqlite shell) through a
debugger.

- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
On Feb 3, 2012 4:35 PM, "Jorge Eliécer Osorio Caro" <
jorgeliecer.oso...@gmail.com> wrote:

> It's caused calling a sqlite_create_module trying to load an extension by
> sqlite3 shell.
>
> 2012/2/3 Stephan Beal 
>
> > 2012/2/3 Jorge Eliécer Osorio Caro 
> >
> > > Good morning every one,
> > >
> > > I having a issue when try to create a sqlite3_create_module.
> > >
> > > when try to load my extension im getting that error "Segmentation
> fault",
> > > cause the sqlite3 cash. i dont know how it happend its my code:
> > >
> > > http://paste.ideaslabs.com/show/OPNHBY7xPG
> >
> >
> > A segfault can be caused by at least 300 million different things. The
> > easiest way to figure out where the problem is is to run your app through
> > gdb (or equivalent) and get a backtrace after it crashes.
> >
> > --
> > - stephan beal
> > http://wanderinghorse.net/home/stephan/
> > http://gplus.to/sgbeal
> > ___
> > 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


  1   2   >