In Windows, use vc6.0 to call SQLite for the first time using C)

Source: Internet
Author: User
Author: zieckey (zieckey@yahoo.com.cn)

All rights reserved!

1. Download sqlitewindows
We can download the Windows version of SQLite from the following websites.
Http://www.sqlite.com.cn/bbs/topicdisp.asp? Tid = 182 & topage = 1 # gotolast
Download the three files:
Download SQLite 3.3.7
Windows
Sqlite-3_3_7.zip. This is the Windows Executable File for SQLite.
Sqlitedll-3_3_7.zip this is SQLite Windows library file
Sqlite-source-3_3_7.zip this is SQLite Windows source code file

If you create a data library under windows, then sqlite-3_3_7.zip is required.
If you program in windows, then sqlitedll-3_3_7.zip1_sqlite-source-3_3_7.zip is required.
If you study the data library in windows, then sqlite-source-3_3_7.zip is required.

2. Compile the Windows lib File

For details, see: VC ++ uses transactions to write sqlite3 databases.
Http://www.sqlite.com.cn/POParticle/4/106.Html

The package we downloaded above does not contain the Lib file, so I compile the Windows lib file myself.
Here is the specific method implemented with VC:

Start a command line and enter the installation directory of VC. My directory is D: \ Microsoft Visual Studio \ vc98 \ bin
There is a lib.exe file in this directory, right. using it, we can create the sqlite3.lib file we need,
Put the sqlite3.def file in the sqlite-source-3_3_7.zip package downloaded by the user in the same directory,
Or you can use the absolute path, and then enter the following command in the command line.

D: \ Microsoft Visual Studio \ vc98 \ bin> lib/machine: ix86/DEF: SQLite. Def

In this way, we get a sqlite3.lib file.

3. Compile the first C-sqlite3 with VCProgram

Compile a simple C program named opendbsqlite. c In an editor as follows:

// Name: opendbsqlite. c
// This file is used to test C/C ++ API for SQLite in vc6.0 on Windows Platform
// Author: zieckey
// 2006/11/5

# Include <stdio. h>

# Include "sqlite3.h"

Int main (void)
{
Sqlite3 * DB = NULL;
Char * zerrmsg = 0;
Int RC;
Rc = sqlite3_open ("zieckey. DB", & dB); // open the specified database file. If it does not exist, a database file with the same name will be created.
If (RC)
{
Fprintf (stderr, "can't open database: % s \ n", sqlite3_errmsg (db ));
Sqlite3_close (db );
Exit (1 );
}
Else printf ("Open zieckey. DB successfully! \ N ");

Sqlite3_close (db); // close the database
Return 0;
}

 

Open vc6.0, create a project, and add opendbsqlite. C to the project.
In addition, copy the sqlite3.h sqlite3.lib sqlite3.dll file to our project directory.
Final project-> Settings find the object/library modules on the Link tab: Fill in sqlite3.lib at the end.
If there is a link, use a space to separate it.

Compile and run the program now. No problem occurs.
The final running result is as follows:

Open zieckey. DB successfully!
Press any key to continue

Haha, our first Windows SQLite program was so successful.

conclusion: for the first time in windows, we use vc6.0 to use SQLite to implement the first simple C program.
This is a good start. We hope that new users can use this example to start their windows SQLite journey.
at the same time, I hope more experts can write their own experiences so that future generations can observe and learn. thank you!

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.