The basics of C + + SQLite

Source: Internet
Author: User
Tags sqlite sqlite database

Article directory:

1. Download SQLite3 Source code:

2. Download the SQLite3.dll file:

3. Generate the SQLite3.lib file:

4. Generate or download the SQLite3 Shell file:

5. Create a database and a data table:

6. Summary:

               

1. Download SQLite3 Source code:

It's been a long time, but it's really not going to work with C + + to manipulate the database.

All the time the project about the database seems to be using. Net to go OK, like SQLite,

Now the project is to use the sqlite.net, there is anything in C # direct Operation Sqlite.net,

And the relatively low-level stuff is done in C + + and encapsulated as a DLL for C # calls OK.

But sometimes when you write something small, there may be some data that needs to be stored locally,

Previously, in order to chart a simple, directly stored files, but if the relative privacy point of things,

I think it's better to have a database, it's not SQLite3. Look at that, huh ?

SQLite3 is intended for use by C + + code and, if it is. Net, it has to be sqlite.net.

Talk less, get to the point, first we need to download a good SQLite3 of relevant documents,

Website address: http://www.sqlite.org/download.html

We first download is the source of the SQLite3, after downloading, you can extract it out, and then you will see 4 C + + files.

And we always need the header files in C + + every time we use SQLite3 sqlite3.h

2. Download SQLite3.dll:

Then you need to download the DLL file for the SQLite3 and export the library,

After downloading you can extract out, you will find only SQLite3.dll and sqlite3.def two files,

3. Generate the SQLite3.lib file:

You know that a. def file can be used to define the export of an API in a DLL.

So we can open sqlite3.def to see that the API name defined in it is the API exported by SQLite3.dll,

If you want to link to other DLLs, you have to have the DLL's export library, which is the. lib file,

And we don't have an export file here (Lib) What do we do? No, it's OK to generate a. Lib file based on a DLL and a. def file.

First copy the SQLite3.dll and sqlite3.def files to the Bin folder in the VS installation directory.

For example, I installed the VS2010, and the default is installed under the C:\Program files\ directory,

Then you need to copy the above two files to the following directory:

C:\Program Files\Microsoft Visual Studio 10.0\vc\bin

Then open the Visual Studio command prompt and navigate to the directory above,

Then enter the command:lib/def:sqlite3.def/machine:ix86,

You will then find that the SQLite3.lib file has been generated in the Bin directory.

4. Generate or download the SQLite3 Shell file:

What about this SQLite3 Shell file, which is used to create a SQLite3 database Ah, create a table ah such things,

In plain words is a SQLite Admin console interface, of course, the console this thing is not very useful,

So you might want to consider a different tool with GUI to manage your SQLite3 database.

There is a good tool, called database.net, what a mess of the database it can be connected up, However, support for the. Net Framework is needed.

For this SQLite3 Shell file you can download it directly from the official website of SQLite,

Then, in addition to downloading SQLite3 Shell tools, we can also compile the SQLite source code to generate this tool,

We have downloaded the source code of SQLite3, and there is a file called shell.c in the source code.

In fact, this file can be used to handle SQLite3 shell commands,

So we can create a new Console project directly under the VS2010,

then copy the 4 c\c++ files in the source code into the project, then compile directly,

You can also get SQLite3 's Shell tool SQLite3.exe.

                                                

5. Create a database and a data table:

                                                

Here's a tricky way to use SQLite3 's Shell tool,

The following example is a very simple way to create a DataBase using SQLite3 's Shell tool,

Then create a Table, and then insert a few records, check it OK.

Just look at the following for specific commands:

First locate your SQLite3.exe in the command line, which is the directory where the shell program is located:

For example, the directory where my SQLite3.exe is located:

E:\Code\SQLite\sqlite-shell-win32-x86-3071000

                                                

Then enter the command sqlite3 testdb.db to create the SQLite database,

                                                

Then enter the command CREATE TABLE testdb_id (ID int, number int) to make the data table testdb_id

then enter the command; The command to create the table above is thus executed.

                                                

After executing these commands, you find the TESTDB.DB database you created in the same location as your Shell program, SQLite3.exe.

                                                

In fact, the above way of creating a database is too troublesome, it is better to use database.net directly to do, a lot of convenience,

For example, I use Database.net to open the Testdb.db database we created above, it is convenient to use this tool to manage the database.

                                                

                                                

6. Summary:

                                                

Okay, this post is over here, and the article doesn't really say anything useful,

It's just some sort of journal record about the environment of SQLite.

Just for those little white people who have not manipulated the SQLite3, they may have a role,

of course, I am also a small white, so I do this article to make a record.

The following chapter will be written in c\c++ under the face of some specific operation of SQLite.

The basics of C + + SQLite

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.