Class: Baza::Driver::Sqlite3Java
- Inherits:
-
JdbcDriver
- Object
- BaseSqlDriver
- JdbcDriver
- Baza::Driver::Sqlite3Java
- Defined in:
- lib/baza/driver/sqlite3_java.rb
Overview
This class handels SQLite3-specific behaviour.
Defined Under Namespace
Classes: Column, Columns, Commands, Index, Indexes, Table, Tables, UnbufferedResult
Constant Summary
Constants inherited from BaseSqlDriver
BaseSqlDriver::SELECT_ARGS_ALLOWED_KEYS
Instance Attribute Summary collapse
-
#mutex_statement_reader ⇒ Object
readonly
Returns the value of attribute mutex_statement_reader.
Attributes inherited from JdbcDriver
Attributes inherited from BaseSqlDriver
#cols, #conn, #db, #indexes, #sep_col, #sep_database, #sep_index, #sep_table, #sep_val, #tables
Class Method Summary collapse
- .args ⇒ Object
-
.from_object(args) ⇒ Object
Helper to enable automatic registering of database using Baza::Db.from_object.
Instance Method Summary collapse
-
#escape(string) ⇒ Object
Escapes a string to be safe to used in a query.
-
#initialize(db) ⇒ Sqlite3Java
constructor
Constructor.
- #reconnect ⇒ Object
- #transaction ⇒ Object
Methods inherited from JdbcDriver
#close, #query, #query_ubuf, #result_set_killer
Methods inherited from BaseSqlDriver
#count, #delete, #escape_column, #escape_database, #escape_index, #escape_table, #insert, #insert_multi, #select, #single, #sql_make_where, #sqlval, #supports_multiple_databases?
Constructor Details
#initialize(db) ⇒ Sqlite3Java
Constructor. This should not be called manually.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/baza/driver/sqlite3_java.rb', line 28 def initialize(db) super @path = @db.opts[:path] if @db.opts[:path] @preload_results = true if @db.opts[:conn] @conn = @db.opts[:conn] else org.sqlite.JDBC reconnect end end |
Instance Attribute Details
#mutex_statement_reader ⇒ Object (readonly)
Returns the value of attribute mutex_statement_reader.
5 6 7 |
# File 'lib/baza/driver/sqlite3_java.rb', line 5 def mutex_statement_reader @mutex_statement_reader end |
Class Method Details
.args ⇒ Object
20 21 22 23 24 25 |
# File 'lib/baza/driver/sqlite3_java.rb', line 20 def self.args [{ label: "Path", name: "path" }] end |
.from_object(args) ⇒ Object
Helper to enable automatic registering of database using Baza::Db.from_object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/baza/driver/sqlite3_java.rb', line 8 def self.from_object(args) if args[:object].class.name == "Java::OrgSqlite::SQLiteConnection" return { type: :success, args: { type: :sqlite3_java, conn: args[:object] } } end end |
Instance Method Details
#escape(string) ⇒ Object
Escapes a string to be safe to used in a query.
50 51 52 53 54 |
# File 'lib/baza/driver/sqlite3_java.rb', line 50 def escape(string) # This code is taken directly from the documentation so we dont have to rely on the SQLite3::Database class. This way it can also be used with JRuby and IronRuby... # http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html string.to_s.gsub(/'/, "''") end |
#reconnect ⇒ Object
42 43 44 45 46 47 |
# File 'lib/baza/driver/sqlite3_java.rb', line 42 def reconnect raise "No path was given." unless @path @stmt = nil @conn = java.sql.DriverManager.getConnection("jdbc:sqlite:#{@path}") end |
#transaction ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/baza/driver/sqlite3_java.rb', line 56 def transaction query_no_result_set("BEGIN TRANSACTION") begin yield @db query_no_result_set("COMMIT") rescue query_no_result_set("ROLLBACK") raise end end |