Getting Started with Cocos2d-x (13) saving data using SQLite

Source: Internet
Author: User
Tags error code sqlite

First download SQLite source code, a total of 4 files, added to the project

Include header file:

#include "Sqlite3.h"

To create or open a database:

Open a database file and, if not, create a database file   
int result=sqlite3_open ("game.db", &pdb);  
If (Result!= sqlite_ok)   
{  
    cclog ("Open database failed, error code:%d, error reason:%s\n", cause, errmsg);   
}  
      
Creates a table, sets the ID as the primary key, and automatically increases   
sqlite3_exec (PDB, CREATE TABLE htable (HID integer PRIMARY key autoincrement, name text), NUL L, NULL, &errmsg);

In the resources directory, you can see a game.db database file appears.

Inserting data

Insert Data   
sqlstr= "insert into htable (name) VALUES (' Henn ')";   
Sqlite3_exec (PDB, sqlstr, NULL, NULL, &ERRMSG);

Open game.db look to see:

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.