A connection to a Sqlite3 database

Introduced properties

fun close

sqlite3 :: Sqlite3DB :: close

Close this connection to the DB and all open statements
fun create_table(rest: Text): Bool

sqlite3 :: Sqlite3DB :: create_table

Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by rest
init defaultinit(native_connection: NativeSqlite3)

sqlite3 :: Sqlite3DB :: defaultinit

fun error: nullable String

sqlite3 :: Sqlite3DB :: error

The latest error message, or null if there is none
fun execute(sql: Text): Bool

sqlite3 :: Sqlite3DB :: execute

Execute the sql statement and return true on success
fun insert(rest: Text): Bool

sqlite3 :: Sqlite3DB :: insert

Insert in the DB with a statement beginning with "INSERT ", followed by rest
fun is_open: Bool

sqlite3 :: Sqlite3DB :: is_open

Is this connection to the DB open?
protected fun is_open=(is_open: Bool)

sqlite3 :: Sqlite3DB :: is_open=

Is this connection to the DB open?
fun last_insert_rowid: Int

sqlite3 :: Sqlite3DB :: last_insert_rowid

Returns the id for the last successful insert on the current connection.
init open(path: Text)

sqlite3 :: Sqlite3DB :: open

Open a connection to the database file at path
fun prepare(sql: Text): nullable Statement

sqlite3 :: Sqlite3DB :: prepare

Prepare and return a Statement, return null on error
fun replace(rest: Text): Bool

sqlite3 :: Sqlite3DB :: replace

Replace in the DB with a statement beginning with "REPLACE", followed by rest
fun select(rest: Text): nullable Statement

sqlite3 :: Sqlite3DB :: select

Select from the DB with a statement beginning with "SELECT ", followed by rest

Redefined properties

redef type SELF: Sqlite3DB

sqlite3 $ Sqlite3DB :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun close

sqlite3 :: Sqlite3DB :: close

Close this connection to the DB and all open statements
fun create_table(rest: Text): Bool

sqlite3 :: Sqlite3DB :: create_table

Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by rest
init defaultinit(native_connection: NativeSqlite3)

sqlite3 :: Sqlite3DB :: defaultinit

fun error: nullable String

sqlite3 :: Sqlite3DB :: error

The latest error message, or null if there is none
fun execute(sql: Text): Bool

sqlite3 :: Sqlite3DB :: execute

Execute the sql statement and return true on success
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun insert(rest: Text): Bool

sqlite3 :: Sqlite3DB :: insert

Insert in the DB with a statement beginning with "INSERT ", followed by rest
fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_open: Bool

sqlite3 :: Sqlite3DB :: is_open

Is this connection to the DB open?
protected fun is_open=(is_open: Bool)

sqlite3 :: Sqlite3DB :: is_open=

Is this connection to the DB open?
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun last_insert_rowid: Int

sqlite3 :: Sqlite3DB :: last_insert_rowid

Returns the id for the last successful insert on the current connection.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
init open(path: Text)

sqlite3 :: Sqlite3DB :: open

Open a connection to the database file at path
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun prepare(sql: Text): nullable Statement

sqlite3 :: Sqlite3DB :: prepare

Prepare and return a Statement, return null on error
fun replace(rest: Text): Bool

sqlite3 :: Sqlite3DB :: replace

Replace in the DB with a statement beginning with "REPLACE", followed by rest
fun select(rest: Text): nullable Statement

sqlite3 :: Sqlite3DB :: select

Select from the DB with a statement beginning with "SELECT ", followed by rest
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram sqlite3::Sqlite3DB Sqlite3DB core::Object Object sqlite3::Sqlite3DB->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

sqlite3 $ Sqlite3DB
# A connection to a Sqlite3 database
class Sqlite3DB
	private var native_connection: NativeSqlite3

	# Is this connection to the DB open?
	var is_open = false

	# All `Statement` opened from this connection that must be closed with this connection
	private var open_statements = new Array[Statement]

	# Open a connection to the database file at `path`
	init open(path: Text)
	do
		init(new NativeSqlite3.open(path.to_cstring))
		if native_connection.is_valid then is_open = true
	end

	# Close this connection to the DB and all open statements
	fun close
	do
		if not is_open then return

		is_open = false

		# close open statements
		for stmt in open_statements do if stmt.is_open then
			stmt.close
		end

		native_connection.close
	end

	# Prepare and return a `Statement`, return `null` on error
	fun prepare(sql: Text): nullable Statement
	do
		var native_stmt = native_connection.prepare(sql.to_cstring)
		if native_stmt.address_is_null then return null

		var stmt = new Statement(native_stmt)
		open_statements.add stmt
		return stmt
	end

	# Execute the `sql` statement and return `true` on success
	fun execute(sql: Text): Bool
	do
		var err = native_connection.exec(sql.to_cstring)
		return err.is_ok
	end

	# Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by `rest`
	#
	# This method does not escape special characters.
	fun create_table(rest: Text): Bool do return execute("CREATE TABLE " + rest)

	# Insert in the DB with a statement beginning with "INSERT ", followed by `rest`
	#
	# This method does not escape special characters.
	fun insert(rest: Text): Bool do return execute("INSERT " + rest)

	# Replace in the DB with a statement beginning with "REPLACE", followed by `rest`
	#
	# This method does not escape special characters.
	fun replace(rest: Text): Bool do return execute("REPLACE " + rest)

	# Select from the DB with a statement beginning with "SELECT ", followed by `rest`
	#
	# This method does not escape special characters.
	fun select(rest: Text): nullable Statement do return prepare("SELECT " + rest)

	# TODO add more prefix here as needed

	# The latest error message, or `null` if there is none
	fun error: nullable String
	do
		if not native_connection.is_valid then
			var err = sys.sqlite_open_error
			if err.is_ok then return null
			return err.to_s
		end

		var err = native_connection.error
		if err.is_ok then return null
		return err.to_s
	end

	# Returns the id for the last successful insert on the current connection.
	fun last_insert_rowid: Int do return native_connection.last_insert_rowid
end
lib/sqlite3/sqlite3.nit:25,1--113,3