Discover qt sqlite select example, include the articles, news, trends, analysis and practical advice about qt sqlite select example on alibabacloud.com
#open3. When programming, be careful to fill in qsqlite, not SQLiteQsqldatabase database = Qsqldatabase::adddatabase ("Qsqlite");4. When using the Qsqldatabase::adddatabase function, if it is a temporary object, then name it, for example (the key is the second parameter):Qsqldatabase LocalDB = qsqldatabase::adddatabase ("Qsqlite", "old_db");If you do not write this second argument, then the new connection will be treated as a default connection, so th
results are exactly the same as those in the previous example (normal data insertion), but they are much better than the former in terms of execution efficiency.
4. Data Query:
Data Query is the most basic function provided by each relational database. The following code example shows how to obtain data through the SQLite API.1). Create a test data table.2) Inse
record, so we call it a result set.while (Query.next ()) QString name = Query.value (0). toString (); Returns the index value of the "Name" field "Justin", Value (i) returns the values of the I field, 0 means that name,1 represents ageint id = query.value (1). ToInt (); seek (int n): query points to the nth record of the result set. Specify the current location first (): query points to a record in the result set. Last (): Query points to the final record of the result set. Next (): query point
qsqlrelationaltablemodel->inheritsqsqltablemodel-> Inheritsqsqlquerymodel->inheritsqabstracttablemodel->inheritsqabstractitemmodel-> InheritsV: qsqlrelationaltablemodel--This class provides an editable data model for a single-sheet database table that supports foreign keys, except that they are not different from Qsqltablemodel.Model->setrelation (2,qsqlrelation ("course", "id", "name")); Set the foreign key//student The third property of the table to the foreign key of the ID property of the c
SQLite tutorial (13): C language programming example code (1), sqlite programming example
1. Get the table Schema information:
1) dynamically create a table.
2) obtain the table field information, such as the number of fields and the type of each field, based on the API provided by sqlite3.
3). Delete the table.
See th
QT and sqlite3 have been used in recent work. Here we record some of the knowledge points used: specifically, tableview is used in the QT widget to display the content in the SQLite database table.
Suppose there are database files test. DB, tables (ID integer, name nvarchar (20), age integer), and there are several pieces of data ...... (Randomly created tables)
. After installing the arm version of Sqlite3, go to the installation directory Sqlite3_arm The Lib directory, the contents are as follows libsqlite3.a libsqlite3.so libsqlite3.so.0.8.6Libsqlite3.la libsqlite3.so.0 Pkgconfig 2. Copy the libsqlite3.a to your own application directory (for example, my Qtcreator application test_sqlite_static)At the same time copy the Sqlite3_arm's include directory under Sqlite3.h to Test_sqlite_static 3. Under the Test
::database(dbName); }else//否则打开这个数据库,注意带上数据库名 = QSqlDatabase::addDatabase("QSQLITE",dbName);Three. class invocation of the related databaseBecause of the introduction of multiple databases, the corresponding class calls are introduced into the database connection object.3.1 QsqlquerySQL query class, you can execute various SQL directives. The default method of use is QSqlQueryquery(); query.exec("select * from table1");But this situation, in
SQLite, as long as you have used a database, you should not be afraid of it. It is enough to think of it as a simple database, but it only supports limited data. Next, let me talk about how to use it. My environment is vs2008 + QT.
Like most people, I first need to Google the Code. The Code is as follows:
# Include
Run the command to view the result:
Qsqldatabase: qsqlite driver not loadedQsqldatabase: av
Sqlite3 compilation and Installation
------------------------ Arm version ----------------------
1.download sqlite-autoconf-3070602.tar.gz from the official website
2. decompress the package and enter the current directory.
3. Start the configuration and execute the following command (the cross-compilation environment must be configured ):./Configure -- prefix =/usr/local/sqlite_arm -- Host = arm-Linux
4. Start compilation and run the follow
example, the main function), and the declared qsqldatabase object is in the same scope;
If the execution result of qsqlquery can be obtained in the debug debugging status when other functions or scopes of non-qsqldatabase objects are involved, however, the desired results will not be obtained in the non-Debug debugging status (for example, the SELECT statement i
SQL insert statementCsdatabase. executenonquery ("Insert into customer (name, city) values (@ name, @ City)",New{Name ="Microsoft", City ="Redmond"});
// Execute a select SQL statement and map the result to a class Class Queryresult { Public String Name; Public Int Numsales; Public Decimal Totalsales;} queryresult [] Results = Csdatabase. runquery ( @" Select name, count (*), sum (S. To
Just likeAndroid SQLiteStatement compilation and execution AnalysisAll SQL statements in SQLite must be compiled to stmt and then executed.The above article introduces SQLiteStatement compilation and execution at the android level. However, SQLiteStatement can only be used to execute SQL statements without return values or with only one row and one column (1X1), such as INSERT ALERT, the returned results such as S
SQLite implements queries through query, which defines query conditions through a series of parameters.Description of each parameter:
Query () method parameters
corresponding SQL section
Describe
Table
From table_name
Table name
Colums
Select Column1,column2
Array of column names
Selection
where column = value
"Testqtdll_global.h" Class Testqtdllshared_export TestQtDll{public: Testqtdll (); int Add (int a, int b);}; #endif//Testqtdll_hTestqtdll.cpp:#include "testqtdll.h" Testqtdll::testqtdll () {}int testqtdll::add (int a, int b) { return (A + b);}(9), add the Libtestqtdll.so library to the TESTQT project: Select the TESTQT project, right-and ADD library-and External library--> Select libtestqtdll.so (
Android SQLite database use example, androidsqlite
For a brief introduction, mainstream mobile devices such as Android and iPhone all use SQLite as the storage engine for complex data. When we develop applications for mobile devices, we may need to use SQLite to store a large amount of data, so we need to master the
SQLite introduces SQLite as a very popular embedded database. It supports the SQL language and has good performance only by using a small amount of memory. In addition, it is open-source and can be used by anyone.SQLite consists of the following components: SQL Compiler, kernel, backend, and attachment. SQLite makes debugging, modification, and expansion of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.