Original Get database version of SQLite's Learning series

Source: Internet
Author: User
Tags sqlite



The first to understand that SQLite is based on its as a mobile client data storage platform, the following is its official website (https://www.sqlite.org/) about SQLite section of the introduction:



     SQLite is an acid-compliant, lightweight database engine that is contained in a relatively small C library. It is a public domain project created by D.richardhipp. The first alpha version of SQLite was born in May 2000 and has been in existence for 16 years, with the current version 3.12.2. Unlike the common client/server architecture paradigm, the SQLite engine is not a separate process for the program to communicate with, but rather a major part of connecting to a program. So the main communication protocol is the direct API call within the programming language. This has a positive effect on total consumption, delay time, and overall simplicity. Throughout, the database (definition, table, index, and data itself) is stored in a single file on the host host. Its simple design is done by locking the entire data file at the start of a transaction.



  sqlite3.c file to remove the comment information, the entire file size only 25000 lines of code, import into the project, you can always view and debug the relevant code, for the understanding of SQLite is very helpful.



This series of articles mainly uses the C + + language to invoke its API to achieve the purpose of glimpse. In addition, the development environment used in this document is Mac + Clion and is developed based on SQLite 3.7.14来.



  One, to download Sqlite-amalgamation-3071400.zip, and then extract to the folder (its structure directory tree as follows):



    .



├──shell.c



├──sqlite3.c



├──sqlite3.h



└──sqlite3ext.h






Second, create a new Sql_tutorial project, King sqlite3.c and Sqlite3.h files copied to the SQL_SRC directory:



    






Third, the code that calls SQLite in Main.cpp is as follows:



    


#include <iostream> using namespace std;

#include "./sql_src/sqlite3.h" int main() {
    cout << "sqlite libversion : " << sqlite3_libversion() << endl; return 0;
}





Four, because Clion uses the time CMake compiles, needs to add the related SQLite's code compilation option in the CMakeLists.txt:





 
cmake_minimum_required(VERSION 3.3)
project(sql_tutorial1)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp sql_src/sqlite3.c)
add_executable(sql_tutorial1 ${SOURCE_FILES})





About Code invocation Process analysis:



1, the Tracking View sqlite3_libversion () implementation, you can see in sqlite3.h about its declaration:


 
SQLITE_API const char *sqlite3_libversion(void);


2, the concrete realization in the SQLITE3.C:


 
/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
** a pointer to the to the sqlite3_version[] string constant. 
*/
SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }


3, but the definition of sqlite3_version:


 
#ifndef SQLITE_AMALGAMATION
/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
** contains the text of SQLITE_VERSION macro. 
*/
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
#endif


4. The Sqlite_version macro is defined as follows:


#define Sqlite_version        "3.7.14"


Here the const char *sqlite3_libversion (void) {return sqlite3_version;} returns the default is the first element of the array, the address of the array points to the first element of the array, That is, the sqlite_version of the macro definition is returned here.






At this point the entire program's invocation process is parsed, and the call Sqlite3_libversion eventually returns the data version number represented by the sqlite_version in sqlite3.c.



[Get Database version of the Learning series of the original]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.