Can't execute all query!
-
Hi
I'm using sqlite , and want to run this query from sql file:
@
CREATE TABLE "dic2" (
"name" TEXT,
"alias" TEXT
);
insert into dic2 ("name", "alias") values ('12', '12');
insert into dic2 ("name", "alias") values ('123', '123');
insert into dic2 ("name", "alias") values ('123123', 'sdasdasd');
insert into dic2 ("name", "alias") values ('123', 'asdasda');
insert into dic2 ("name", "alias") values ('asd', 'sasdasd');
@table is made but, can't insert values into table! why?
-
Did you get any errors?
-
That's strange. Could you please share your source code. What is your OS?
-
I'm using Windows 7 64bits.
and this is code :
@
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"",
tr("Files (.)"));
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QString line;
QTextStream in(&file);
line = in.readAll();if (mw->dbconnect())
{
QSqlQuery query(line);
}
@ -
The SQL seems OK but try to execute it via "the SQLite command-line shell for accessing and modifying SQLite databases for Windows":http://www.sqlite.org/download.html
Please also consider the option to execute each of your SQL statement is a separate QSqlQuery in your source code.
-
I think the problem is in SQL code. When you declare table and columns names you should not use the "". Moreover, I never saw the TEXT declaration. Try this code:
@
CREATE TABLE dic2 ( name CHAR(10), alias CHAR(10) );insert into dic2 (name, alias) values ('12', '12');
insert into dic2 (name, alias) values ('123', '123');
insert into dic2 (name, alias) values ('123123', 'sdasdasd');
insert into dic2 (name, alias) values ('123', 'asdasda');
insert into dic2 (name, alias) values ('asd', 'sasdasd');
@Before writing SQL statements into Qt applications is always best to test them in a SQL console.
Hope it helps. -
[quote author="Seba84" date="1342383542"]I think the problem is in SQL code. When you declare table and columns names you should not use the "". Moreover, I never saw the TEXT declaration. [/quote]
Good point I didn't spot the quotes at the insert statement. TEXT is SQLite specific data type. Check "SQLite documentation":http://www.sqlite.org/datatype3.html for details.
-
but,its OK!
because qt can execute one query per action!
i should convert my sql code to one code such as this :
@
INSERT INTOcds
(titel
,interpret
,jahr
,id
) VALUES
('Beauty', 'Ryuichi Sakamoto', 1990, 1),
('Goodbye Country (Hello Nightclub)', 'Groove Armada', 2001, 4),
('Glee', 'Bran Van 3000', 1997, 5);
@