I am a novice database, in the creation of a table problems, and finally verified to find out the problem. The following program is a partial excerpt, when creating a database table, the first use of the L24 Createdb, tested, has been output create TestResult Fail,
Query->isactive () is also false, which indicates that the problem is createdb, which means that the qstring should not meet the requirements of the error. Later, one after the other, the final discovery was
The reason for check varchar (100) is that the check is a database keyword.
1 //Create a database file path2Testresultpath = Appdir +"/testreport/";3 qdir My_dir (testresultpath);4 if(!my_dir.exists ())5 My_dir.mkpath (testresultpath);6Testresultpath + ="testresult.db";7 8 //Create a database9Qsqldatabase db = Qsqldatabase::adddatabase ("Qsqlite");Ten //db.sethostname ("easybook-3313b0"); //can omit One Db.setdatabasename (testresultpath); A //db.setusername ("cetg54th"); //To set the database user name, you can omit - //Db.setpassword ("123456"); //To set the database password, you can omit - Db.open (); the if(!Db.isopen ()) - { -Qdebug () <<"DB is not open"; - return; + } - + A //Create a database table atQsqlquery *query =NewQsqlquery ("", DB); - //const QString createdb = "CREATE TABLE TestResult (ID int primary key,testdevice varchar), Project varchar (+), exc varchar (+), display varchar (+), result varchar (+), time varchar (+), check varchar (100)) "; //fail - - ConstQString Createdb ="CREATE TABLE TestResult (ID int primary key,testdevice varchar), Project varchar (+), exc varchar, display varchar (+), result varchar (+), time varchar, viewInfo varchar ( +)";//Success - - if(query->exec (createdb)) inQdebug () <<"Create TestResult Successful"; - Else toQdebug () <<"Create TestResult Fail"; + -Qdebug () << query->isactive ();
Here's a list of database keywords
A
ABSOLUTE ACTION ADD AdminDB
All ALLOCATE alphanumeric ALTER
And any is as
ASC Assertion at AUTHORIZATION
AutoIncrement AVG
B
BAND BEGIN between BINARY
BIT bit_length bnot BOR
BOTH Bxor by BYTE
C
CASCADE cascaded Case CAST
CATALOG CHAR CHARACTER Char_length
Character_length CHECK CLOSE Coalesce
COLLATE COLLATION COLUMN COMMIT
COMP COMPRESSION CONNECT CONNECTION
CONSTRAINT CONSTRAINTS CONTAINER CONTINUE
CONVERT corresponding COUNT COUNTER
CREATE Createdb Cross CURRENCY
Current Current_date Current_time Current_timestamp
Current_User CURSOR
D
DATABASE DATE DATETIME Day
deallocate DEC DECIMAL DECLARE
DEFAULT deferrable DEFERRED DELETE
DESC DESCRIBE Descriptor Diagnostics
DISALLOW DISCONNECT DISTINCT DOMAIN
DOUBLE DROP
E
ELSE END end-exec ESCAPE
EXCEPT EXCEPTION Exclusiveconnect EXEC
EXECUTE EXISTS EXTERNAL EXTRACT
F
FALSE FETCH First FLOAT
FLOAT4 FLOAT8 for FOREIGN
FOUND from
G
General GET GLOBAL GO
GOTO GRANT GROUP GUID
H
Having HOUR
I
IDENTITY ieeedouble Ieeesingle IGNORE
IMAGE IMMEDIATE in INDEX
INDICATOR inheritable initially INNER
INPUT insensitive INSERT INT
INTEGER INTEGER1 INTEGER2 INTEGER4
INTERSECT INTERVAL into is
Isolation
J
JOIN
K
KEY
L
LANGUAGE last leading left
Level like LOCAL LOGICAL
LOGICAL1 LONG longbinary LongChar
Longtext LOWER
M
MATCH MAX MEMO MIN
MINUTE MODULE Money MONTH
N
NAMES National NATURAL NCHAR
NEXT NO not NOTE
NULL nullif Number NUMERIC
O
OBJECT Octet_length of OLEOBJECT
On only OPEN OPTION
OR ORDER OUTER OUTPUT
Overlaps owneraccess
P
PAD PARAMETERS PARTIAL PASSWORD
PERCENT PIVOT POSITION PRECISION
PREPARE PRESERVE PRIMARY PRIOR
Privileges PROC PROCEDURE Public
Q
R
READ REAL REFERENCES RELATIVE
RESTRICT REVOKE Right ROLLBACK
ROWS
S
SCHEMA SCROLL SECOND Section
SELECT Selectschema selectsecurity SESSION
Session_user SET Short Single
SIZE SMALLINT SOME SPACE
SQL SQLCODE SQLERROR SQLSTATE
STRING SUBSTRING SUM System_user
T
TABLE TABLEID Temporary TEXT
Then time TIMESTAMP Timezone_hour
Timezone_minute to TOP TRAILING
TRANSACTION TRANSFORM TRANSLATE Translation
TRIM TRUE
U
UNION UNIQUE uniqueidentifier UNKNOWN
UPDATE updateidentity Updateowner updatesecurity
UPPER USAGE USER USING
V
VALUE VALUES VARBINARY VARCHAR
VARYING VIEW
W
When whenever WHERE with
Work WRITE
X
Y
Year YESNO
Z
ZONE
The above keywords are mainly transferred from http://zhidao.baidu.com/link?url= Rmjbwdmrnxciebfhmxsijf3bzzgb1yw0ywkhughxcyblkmixclmjl8pull-m7saspaaougzpqyflgyph5gq36tjosn7j_ighdlabxbfqrje
In addition, if the use of the database problem is not the above problem, it is recommended to blog http://www.cnblogs.com/findumars/p/4207133.html, hope to help.
Database keywords for the reason that Qt database creation table failed