Sha256: cf5eaeb8d05145d40965db83231267620e4e4436155043a1b6bdd872fbdcbecf

Contents?: true

Size: 1.49 KB

Versions: 109

Compression:

Stored size: 1.49 KB

Contents

class KnjDB_java_sqlite3
  def escape_table
    return "`"
  end
  
  def escape_col
    return "`"
  end
  
  def escape_val
    return "'"
  end
  
  def initialize(knjdb_ob)
    @knjdb = knjdb_ob
    
    if @knjdb.opts[:sqlite_driver]
      require @knjdb.opts[:sqlite_driver]
    else
      require File.dirname(__FILE__) + "/sqlitejdbc-v056.jar"
    end
    
    require "java"
    import "org.sqlite.JDBC"
    @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:" + @knjdb.opts[:path])
    @stat = @conn.createStatement
  end
  
  def query(string)
    begin
      return KnjDB_java_sqlite3_result.new(@stat.executeQuery(string))
    rescue java.sql.SQLException => e
      if e.message == "java.sql.SQLException: query does not return ResultSet"
        #ignore it.
      else
        raise e
      end
    end
  end
  
  def fetch(result)
    return result.fetch
  end
  
  def escape(string)
    if (!string)
      return ""
    end
    
      string = string.gsub("'", "\\'")
    return string
  end
  
  def lastID
    return @conn.last_insert_row_id
  end
end

class KnjDB_java_sqlite3_result
  def initialize(rs)
    @rs = rs
    @index = 0
    
    if rs
      @metadata = rs.getMetaData
      @columns_count = @metadata.getColumnCount
    end
  end
  
  def fetch
    if !@rs.next
      return false
    end
    
    tha_return = {}
    for i in (1..@columns_count)
      col_name = @metadata.getColumnName(i)
      tha_return.store(col_name, @rs.getString(i))
    end
    
    return tha_return
  end
end

Version data entries

109 entries across 109 versions & 2 rubygems

Version Path
knjrbfw-0.0.17 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.16 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.15 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.14 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.13 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.12 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.11 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.10 lib/knj/knjdb/libknjdb_java_sqlite3.rb
knjrbfw-0.0.9 lib/knj/knjdb/libknjdb_java_sqlite3.rb