Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is an extension (called gdx-sqlite) that I wrote which will do most of the work you require. Latest build of this extension can be downloaded from <a href="http://bit.ly/gdx-sqlite">here</a>. The source code and read me are located at: <a href="https://github.com/mrafayaleem/gdx-sqlite">https://github.com/mrafayaleem/gdx-sqlite</a></p> <p>This extension currently supports Android and Desktop platforms. Also, there is no support to open databases located in the assets folder of the Android app. However, this is a pending feature and will be added soon.</p> <p>Follow the instructions in read me to setup your projects for database handling. Following is an example code:</p> <pre><code>package com.mrafayaleem.gdxsqlitetest; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.sql.Database; import com.badlogic.gdx.sql.DatabaseCursor; import com.badlogic.gdx.sql.DatabaseFactory; import com.badlogic.gdx.sql.SQLiteGdxException; public class DatabaseTest { Database dbHandler; public static final String TABLE_COMMENTS = "comments"; public static final String COLUMN_ID = "_id"; public static final String COLUMN_COMMENT = "comment"; private static final String DATABASE_NAME = "comments.db"; private static final int DATABASE_VERSION = 1; // Database creation sql statement private static final String DATABASE_CREATE = "create table if not exists " + TABLE_COMMENTS + "(" + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_COMMENT + " text not null);"; public DatabaseTest() { Gdx.app.log("DatabaseTest", "creation started"); dbHandler = DatabaseFactory.getNewDatabase(DATABASE_NAME, DATABASE_VERSION, DATABASE_CREATE, null); dbHandler.setupDatabase(); try { dbHandler.openOrCreateDatabase(); dbHandler.execSQL(DATABASE_CREATE); } catch (SQLiteGdxException e) { e.printStackTrace(); } Gdx.app.log("DatabaseTest", "created successfully"); try { dbHandler .execSQL("INSERT INTO comments ('comment') VALUES ('This is a test comment')"); } catch (SQLiteGdxException e) { e.printStackTrace(); } DatabaseCursor cursor = null; try { cursor = dbHandler.rawQuery("SELECT * FROM comments"); } catch (SQLiteGdxException e) { e.printStackTrace(); } while (cursor.next()) { Gdx.app.log("FromDb", String.valueOf(cursor.getString(1))); } try { dbHandler.closeDatabase(); } catch (SQLiteGdxException e) { e.printStackTrace(); } dbHandler = null; Gdx.app.log("DatabaseTest", "dispose"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload