SQLite database management tools in Cocos2d-x, cocos2d-xsqlite

Source: Internet
Author: User

SQLite database management tools in Cocos2d-x, cocos2d-xsqlite
After the database is created, we may need to check whether the data in the database is successfully inserted. Many people prefer to use graphical interfaces to manage the SQLite database. SQLite graphical interface management tools are many, I recommend using SQLiteStudio tools, http://sqlitestudio.pl /? Act = download. SQLiteStudio supports cross-platform, multi-language, including Chinese. You can export various formats such as SQL, CSV, HTML, and XML.
Start the SQLiteStudio tool. On the interface, choose "Database"> "add Database" from the menu. In the displayed dialog box, select "<project directory> \ proj. win32 \ Debug. win32 \ NotesList. sqlite3 ", NotesList. sqlite3 is generated by the initialization database.

Use SQLiteStudio

In the Add database dialog box, click "OK" to open the database. In the left navigation tree, double-click "NotesList. sqlite3 → table → Note, and then click the data tab on the right to open the Note table. Click the shortcut button below to manage the table.

Open the Note table


Manage table shortcut

In addition, you can use SQLiteStudio to manage databases. SQLiteStudio has powerful functions.



More content please pay attention to the first domestic Cocos2d-x 3.2 version of the book "Cocos2d-x practice: C ++ volume" book exchange discussion site: http://www.c Ocoagame.net
For more exciting video courses, please follow the Cocos course in Zhijie class: http: // v.51w Ork6.com
Welcome to the Cocos2d-x Technology Discussion Group: 257760386 welcome to the knowledge of the iOS classroom public platform


The use of cocos2d-x + VS to make small games, the use of sqlite, In the android transplant can not read the database

Sqlite3.c is used to operate sqlite. The download and use of this library are described in many tutorials.
On win32 and MacOS, this library is not used in particular, but on Android, it cannot be directly read.
The reason why Android cannot read databases is that database operations must have root permissions. That is to say, our applications can only operate database files in a specific directory provided by the system.
In this directory, cocos2.1.3 can be obtained through CCFileUtils: sharedFileUtils ()-> getWritablePath.
That is to say, we need to copy the sliqte library file under the Resource Directory to CCFileUtils: sharedFileUtils ()-> getWritablePath () to operate on it.
In this case, my solution is to implement the following in AppDelegate. cpp:
Bool isFileExist (const char * pFileName)
{
If (! PFileName) return false;
Std: string filePath = CCFileUtils: sharedFileUtils ()-> getWritablePath ();
FilePath + = pFileName;
FILE * pFp = fopen (filePath. c_str (), "r ");
CCLog (filePath. c_str ());
If (pFp)
{
Fclose (pFp );
Return true;
}
Return false;
}
Void copyData (const char * pFileName)
{
Std: string strPath = CCFileUtils: sharedFileUtils ()-> fullPathForFilename (pFileName );
Unsigned long len = 0;
Unsigned char * data = NULL;
Data = CCFileUtils: sharedFileUtils ()-> getFileData (strPath. c_str (), "r", & len );

Std: string destPath = CCFileUtils: sharedFileUtils ()-> getWritablePath ();
DestPath + = pFileName;

FILE * pFp = fopen (destPath. c_str (), "w + ");
Fwrite (data, sizeof (char), len, pFp );
Fclose (pFp );
Delete [] data;
Data = NULL;
}

Bool AppDelegate: applicationDidFinishLaunching ()
{
# If (CC_TARGET_PLATFORM! = CC_TARGET_WIN32) // copy the data file in Android
// Check whether the database file has been extracted
If (isFileExist ("dbd_user_save.db") = false)
{
CopyData ("dbd_user_save.db"); // The sqlite library file to be used
}

# Endif
// Lower

When the program starts, check whether sqlite exists and does not exist. Copy one copy.

Reposted from, and try again
... The remaining full text>

Cocos2d-x using sqlite database, in win32 did not ask you, sqlite3_open under ios can not create a database, the returned value is 14

The db file path is incorrect.
Ios does not support file modification except the document directory

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.