C/C ++ SQLite Basics

Source: Internet
Author: User

ArticleDirectory:

1. Download The 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. Conclusion:

1. Download The sqlite3 source code:

Although it has been a long time to play with C/C ++, I have never done anything about using C/C ++ to play with the database,

It seems that all database-related projects use. Net to get OK, just like SQLite,

The current project uses SQLite. net, and C # is used to directly operate SQLite. net,

At the underlying layer, it is okay to use C/C ++ and package it into a DLL for C # to call.

However, some data may need to be stored locally when you write small items,

In the past, for the sake of simplicity, we saved files directly. However, if we had something relatively private,

I think it is better to have a database. This is not sqlite3. Please pay attention to it,

Sqlite3 is for C/C ++CodeIf it is. net, then SQLite. NET is used,

If you get started, we need to download the relevant sqlite3 files,

Address: http://www.sqlite.org/download.html

We first download the source code of sqlite3. After the download, You can decompress it and then you will see four C/C ++ files.

Every time we use sqlite3 in C/C ++, we always need the header file sqlite3.h.

2. Download sqlite3.dll:

Next, you need to download the DLL file of sqlite3 and export the database,

After downloading, You can decompress the package and find that only two files are available: sqlite3.dll and sqlite3.def,

3. Generate the sqlite3.lib file:

All C/C ++ DLL users know that the. Def file can be used to define API export in a DLL,

So we can open sqlite3.def and check that the API name defined in it is the API exported by sqlite3.dll,

In C/C ++, if you want to link to other DLL files, you must have the DLL export library, that is, the. Lib file,

What should we do if the file (LIB) is not exported here? If no, generate a. Lib File Based on the DLL and. Def files ~

First, copy the sqlite3.dll and sqlite3.def files to the bin folder under the vs installation directory,

For example, if vs2010 is installed and is installed under the c: \ Program Files \ directory by default,

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

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

Open the Visual Studio command prompt and locate the directory above,

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

Then you will find that the sqlite3.lib file has been generated in the bin directory.

4. generate or download the sqlite3 shell file:

The sqlite3 shell file is used to create the sqlite3 database, create tables, and so on,

To put it bluntly, it is a console interface of SQLite Admin. Of course, the console is not easy to use,

So you can consider another tool with GUI to manage your sqlite3 database.

There is a good tool called database. net. It can be connected to any messy database, but it must be supported by. NET Framework.

You can directly download the sqlite3 shell file from the official SQLite website,

In addition to downloading the sqlite3 shell tool, we can also compile SQLiteSource codeTo generate this tool,

We have downloaded the source code of sqlite3, and there is a file named shell. c In the source code,

In fact, this file can be used to process the sqlite3 shell command,

So we can directly create a console project under vs2010,

Then copy the four C \ c ++ files in the source code to the project and compile them directly,

You can also get sqlite3 shell tool sqlite3.exe.

5. Create a database and a data table:

Here, we use the sqlite3 shell tool,

The following example shows how to use the sqlite3 shell tool to create a database,

Then create a table, insert several more records, and query it.

The specific command is as follows:

First, locate your sqlite3.exe or shell in the command line.ProgramDirectory:

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

E: \ code \ SQLite \ sqlite-shell-win32-x86-3071000.

Then run sqlite3 testdb. dB to create the SQLite database,

Run the create table testdb_id (ID int, number INT) command to create the testdb_id data table.

Then enter the command to execute the command for creating the table above.

After executing these commands, you can find the testdb. DB database you created in the location of your shell program, that is, sqlite3.exe.

In fact, the above method of creating a database is too troublesome. It is much easier to directly use database. net,

For example, if I use database. Net to open the testdb. DB database we created above, it is very convenient to use this tool to manage the database.

6. Summary:

Well, this blog post is over here. The above Article does not really cover anything useful,

It's just some history records about the SQLite environment.

It may only be useful for those who have not performed sqlite3,

Of course, I am still a little white, so I wrote this article as a record.

The following chapter is about some specific operations on SQLite in C \ c ++.

Copyright,HuanWelcome to reprint, but please note: Reprinted fromZachary. Xiaozhen-the sky of dreams

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.