SQLite

일반 사용자 어플리케이션 데이터베이스를 위한 사용 목적으로 개발된 오픈 RDBMS로서

별도의 서버와 프로세스 통신 없이 응용 프로그램 내에서 DB처리를 할 수 있고, 

C언어로 작성 되었으며, 일반적인 SQL(Structured Query Language)로 쿼리가 가능하다.

빠른 속도와 이식성, 안정성의 특징을 갖는다.

또한 가장 매력적인 특징 중 하나는 어디서든 실행이 가능하다는 점이고

공개된 도메인으로서 사용 목적에 관계없이 모든 사람이 자유롭게 사용 할 수 있다.

 

 

SQLite Install(설치)

2020년 4월 10일 기준 최신 버전은 3.31.1버전이며,

https://sqlite.com/index.html 에서 다운 가능하다.

 

SQLite Home Page

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bu

sqlite.com

Sqlite-amalgamtion-3310100.zip 설치하고 압축을 해제한다.

 

 

 

압축해제 후 결과물

 

 

Static Library 생성

 

나는 VIsualStudio2005 환경에서 정적라이브러리를 생성하였다.

프로젝트명을 sqlite3으로 하고, PreCompiled Header를 체크해제하고, Static Library로 프로젝트를 생성하여

디버그 모드와 릴리즈 모드로 각각 빌드를 하여 sqlite3.lib 파일을 생성하였다.

SQLite Sample Project 생성

 

TestSQlite라는 프로젝트를 생성하여 앞에서 만든 라이브러리와 헤더파일을 각각 링크해준다.

 

아래와 같이 테스트 코드를 작성하여 보고 Test.db 파일이 실제로 생성되는지 확인

// TestSQLite.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "sqlite3.h"
int _tmain(int argc, _TCHAR* argv[])
{
	sqlite3* myDB;

	if( SQLITE_OK != sqlite3_open("Test.db", &myDB) )
	{
		cout << "Not Accessed" << endl;
	}




	sqlite3_close(myDB);
	

	return 0;
}

 

생성된 테이블 확인하기

 

// TestSQLite.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "sqlite3.h"
int _tmain(int argc, _TCHAR* argv[])
{
	sqlite3* myDB = NULL;
	sqlite3_stmt *stmt = NULL;

	if( SQLITE_OK != sqlite3_open("Test.db", &myDB) )
	{
		cout << "Not Accessed" << endl;
	}

	char *sql = "CREATE TABLE SmartID(ID INTEGER, NAME TEXT);";

	if( SQLITE_OK == sqlite3_prepare_v2(myDB, sql, -1, &stmt, 0) )
	{
		sqlite3_step(stmt);
	}
	else
	{
		cout << "can not create table" << endl;

	}



	sqlite3_finalize(stmt);
	sqlite3_close(myDB);

	return 0;
}

 

다음 코드를 통하여  정수형 타입을 갖는 ID,

문자열 NAME 의 Attribute(어트리뷰트)를 갖는 SmartID 테이블을 생성한다.

 

그리고 DB Browser를 통하여 생성된 테이블을 확인해보자.

 

 

SmartID라는 테이블이 정상적으로 생성되었고, 앞으로 이 테이블을 이용하여 사용자의

ID와 Name의 데이터를 관리 할 수있게 되었다. 

 

DB Browser 설치 : https://sqlitebrowser.org/

 

DB Browser for SQLite

DB Browser for SQLite The Official home of the DB Browser for SQLite Screenshot What it is DB Browser for SQLite (DB4S) is a high quality, visual, open source tool to create, design, and edit database files compatible with SQLite. DB4S is for users and dev

sqlitebrowser.org

 

 

+ Recent posts