Skip to content

Pluma is a SQLite wrapper for Java (and Android).

License

Notifications You must be signed in to change notification settings

pietrocaselani/pluma

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pluma

Pluma is a SQLite wrapper for Java and Android, based on iOS FMDB.

#Usage

There are three main classes in Pluma:

  • Database - Represents a single SQLite database. Used for executing SQL statements.
  • ResultSet - Represents the results of a query executed by Database.
  • Statement - Represents a single compiled SQL statement. Use Database.prepareStatement.

Almost all operations performed by the Database and ResultSet throws a SQLiteException.

Database creation

Database database = new Database("/path/db.sqlite");
database.open();

Executing Updates

Any sort of SQL statement which is not a SELECT statement qualifies as an update.

database.executeUpdate("CREATE TABLE people (id INTEGER PRIMARY KEY, name TEXT)");

Executing Queries

ResultSet resultSet = database.executeQuery("SELECT id, name FROM people");
while (resultSet.next()) {
  int id = resultSet.getInt(0);
  String name = resultSet.getString(1);
}

In a loop, the next() closes the ResultSetautomatically when the statement is done. Otherwise you should always call close() on ResultSet

Statement Parameters

  • List
List<Object> args = Arrays.asList(5, 10);
ResultSet resultSet = database.executeQuery("SELECT name FROM people WHERE id = ? OR id = ?", args);

or

ResultSet resultSet = database.executeQuery("SELECT name FROM people WHERE id = ? OR id = ?", 5, 10);
  • Named parameters
Map<String, Object> argsMap = new HashMap<String, Object>();
argsMap.put("personId", 5);
ResultSet resultSet = database.executeQuery("SELECT name FROM people WHERE id = :personId", argsMap);

About

Pluma is a SQLite wrapper for Java (and Android).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 50.7%
  • C++ 35.6%
  • C 10.4%
  • CMake 2.0%
  • Other 1.3%