PDA

View Full Version : This application has requested the runtime to terminate it in an unusual way



phapha
30th October 2011, 17:48
Hi all,
I m trying to create 3tables in my SQlite database. I use the following code.


QSqlQuery query;
query.exec("create table user (UPI int primary key, firstname varchar, lastname varchar, cos int )");
query.exec("insert into person values(380142, 'Danny', 'Young',10)");
query.exec("insert into person values(102222, 'Christine', 'Holand',23)");

//The following requests create the tables, but don't insert the data
query.exec("create table destination (number int primary key,type varchar)");
query.exec("insert into destination values(0022921301074, 'local')");
query.exec("insert into destination values(002217780216, 'international')");

//The requests below gives an error message
query.exec("create table callId (id int primary key, ext int)")/*, day varchar, moment varchar,duree int,transfer int, transferExist bool,cosExist bool, number int, cos int)")*/;
query.exec("insert into callId values(' ', '2011-10-28','17:25',128,3300,'true','false',0022921301074, ' ')");
query.exec("insert into callId values(' ', '2011-10-29','00:29',128,' ','false','true',002217780216,10)");


The error message is "This application has request the Runtime to terminate at an unusual way".

And the debugger show the following message :
Début du débogageASSERT: "idx >= 0 && idx < s" in file ..\..\include/QtCore/../../../../../../ndk_buildrepos/qt-desktop/src/corelib/tools/qvarlengtharray.h, line 107
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
Fin du débogage

Kindly help me;
Thanks

norobro
30th October 2011, 17:58
Don't know if this causes the crash or not but:

QSqlQuery query;
query.exec("create table user (UPI int primary key, firstname varchar, lastname varchar, cos int )");
query.exec("insert into person values(380142, 'Danny', 'Young',10)");
query.exec("insert into person values(102222, 'Christine', 'Holand',23)");The above inserts will fail with the wrong table name.
query.exec("create table callId (id int primary key, ext int)")/*, day varchar, moment varchar,duree int,transfer int, transferExist bool,cosExist bool, number int, cos int)")*/;
query.exec("insert into callId values(' ', '2011-10-28','17:25',128,3300,'true','false',0022921301074, ' ')");
query.exec("insert into callId values(' ', '2011-10-29','00:29',128,' ','false','true',002217780216,10)");You create a table with two columns and try to insert nine columns. These inserts will fail also.

phapha
30th October 2011, 19:37
You create a table with two columns and try to insert nine columns. These inserts will fail also.

Even when I try with the nine columns I have the same error.
Here is my code.


query.exec("create table callId (id int primary key,ext int,day varchar(10),moment varchar(5),duree int,transfer int,transferExist int,cosExist int,number int,cos int)");
query.exec("insert into callId values(' ', '2011-10-28','17:25',128,3300,'true','false',0022921301074, ' ')");
query.exec("insert into callId values(' ', '2011-10-29','00:29',128,' ','false','true',002217780216,10)");


Need your help.:(

norobro
30th October 2011, 20:18
Please post the stack trace or at least the last line in the stack trace that is your code.

phapha
30th October 2011, 21:02
Unfortunately, there is no stack trace
7047

norobro
30th October 2011, 22:44
Is that a debug build? Do a "Build->Clean All", a "Build->Rebuild All" and Run

If that doesn't work, set a breakpoint and step through your program until it crashes.

Other than that, can't help with Windows. Sorry.

ChrisW67
30th October 2011, 22:54
There is nothing in the lines you have posted that should cause anything like a program crash. (See below for reasons it won't work anyway)

Rebuild the project from scratch: does the problem still occur?
Comment out those lines: does the crash still occur?
Single step through those lines, including stepping into the Qt code, and tell us exactly which causes the crash and how it arrived there?


Other observations:

It is unusual that, in a table with only two varchar fields, you insert everything as a string. Sqlite should allow this, but you might consider fixing the inserts.
Sqlite treats 'bool' as integers with 1 == true, 0 == false, not strings 'true' and 'false'. While it will store and retrieve these faithfully it will treat both as false (i.e. their value as integers is zero) in boolean expressions.
Your table is defined with 10 columns (not 9) and you are trying to insert 9 values. The SQL is broken.
Your second insert will fail with a duplicate key. Sqlite will not manufacture an id column value for you unless the column is declared "integer primary key autoincrement" (literally) and you either insert a NULL into the column, or omit the column from the insert.
You should get into the habit of explicitly nominating columns in insert statements so that adding a column to a table does not break every existing insert. For example:
create table a (id integer primary key autoincrement, b varchar(10));
insert into a (b) values ('Hello');
select * from a;
If you need the 'number' column to preserve the leading zeroes on your (I assume) phone numbers then you must use a varchar field.

phapha
31st October 2011, 00:00
There is nothing in the lines you have posted that should cause anything like a program crash. (See below for reasons it won't work anyway)

Rebuild the project from scratch: does the problem still occur?

yes


Comment out those lines: does the crash still occur?

No


Single step through those lines, including stepping into the Qt code, and tell us exactly which causes the crash and how it arrived there?

When I comment out the fllowing line, there is no more crash. But I need to delete the .db file created by the sqlite database before compiling again. If I don't do that, the crash occurs agin even if I comment the line.


query.exec("create table callId (id int primary key,ext int,day varchar(10),moment varchar(5),duree int,transfer int,transferExist int,cosExist int,number int,cos int)");




Other observations:

It is unusual that, in a table with only two varchar fields, you insert everything as a string. Sqlite should allow this, but you might consider fixing the inserts.
Sqlite treats 'bool' as integers with 1 == true, 0 == false, not strings 'true' and 'false'. While it will store and retrieve these faithfully it will treat both as false (i.e. their value as integers is zero) in boolean expressions.
Your table is defined with 10 columns (not 9) and you are trying to insert 9 values. The SQL is broken.
Your second insert will fail with a duplicate key. Sqlite will not manufacture an id column value for you unless the column is declared "integer primary key autoincrement" (literally) and you either insert a NULL into the column, or omit the column from the insert.
You should get into the habit of explicitly nominating columns in insert statements so that adding a column to a table does not break every existing insert. For example:
create table a (id integer primary key autoincrement, b varchar(10));
insert into a (b) values ('Hello');
select * from a;
If you need the 'number' column to preserve the leading zeroes on your (I assume) phone numbers then you must use a varchar field.
[/QUOTE]
Thank you ChrisW67. I've just applied all your remarks. they were really helpful. But, I still have a the error message.
Here is my code.



query.exec("create table callId (id integer primary key autoincrement,ext int,day varchar(10),moment varchar(5),duree int,transfer int,transferExist bool,cosExist bool,number varchar(20),cos int)");
query.exec("insert into callId values(NULL, 3300,'2011-10-28','17:25',128,3333,0,1,0022921301074,NULL)");
query.exec("insert into callId values(NULL, 3310,'2011-10-29','00:29',128,NULL,1,0,002217780216,10)");



Thanks Norobro to have replied to me.

ChrisW67
31st October 2011, 01:49
Does the problem go away if you use ":memory:" as the database file name? That is make a transient, in-memory database.