baza 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +58 -13
 - data/VERSION +1 -1
 - data/baza.gemspec +15 -3
 - data/include/db.rb +871 -865
 - data/include/drivers/mysql/mysql.rb +104 -297
 - data/include/drivers/mysql/mysql_column.rb +133 -0
 - data/include/drivers/mysql/mysql_columns.rb +4 -127
 - data/include/drivers/mysql/mysql_index.rb +76 -0
 - data/include/drivers/mysql/mysql_indexes.rb +0 -73
 - data/include/drivers/mysql/mysql_result.rb +42 -0
 - data/include/drivers/mysql/mysql_result_java.rb +61 -0
 - data/include/drivers/mysql/mysql_result_mysql2.rb +26 -0
 - data/include/drivers/mysql/mysql_result_unbuffered.rb +72 -0
 - data/include/drivers/mysql/mysql_sqlspecs.rb +1 -1
 - data/include/drivers/mysql/mysql_table.rb +361 -0
 - data/include/drivers/mysql/mysql_tables.rb +23 -381
 - data/include/drivers/sqlite3/libknjdb_java_sqlite3.rb +17 -22
 - data/include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb +13 -13
 - data/include/drivers/sqlite3/sqlite3.rb +39 -105
 - data/include/drivers/sqlite3/sqlite3_column.rb +146 -0
 - data/include/drivers/sqlite3/sqlite3_columns.rb +17 -149
 - data/include/drivers/sqlite3/sqlite3_index.rb +55 -0
 - data/include/drivers/sqlite3/sqlite3_indexes.rb +0 -52
 - data/include/drivers/sqlite3/sqlite3_result.rb +35 -0
 - data/include/drivers/sqlite3/sqlite3_result_java.rb +39 -0
 - data/include/drivers/sqlite3/sqlite3_table.rb +399 -0
 - data/include/drivers/sqlite3/sqlite3_tables.rb +7 -403
 - data/include/idquery.rb +19 -19
 - data/include/model.rb +139 -139
 - data/include/model_handler_sqlhelper.rb +74 -74
 - data/spec/support/driver_columns_collection.rb +17 -0
 - metadata +14 -2
 
| 
         @@ -29,11 +29,16 @@ class Baza::Driver::Mysql::Tables 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  #ignore.
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
                tables = []
         
     | 
| 
      
 33 
     | 
    
         
            +
                list(name: table_name) do |table_obj|
         
     | 
| 
       33 
34 
     | 
    
         
             
                  return table_obj if table_obj.name == table_name
         
     | 
| 
       34 
35 
     | 
    
         
             
                end
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
      
 37 
     | 
    
         
            +
                list do |table_obj|
         
     | 
| 
      
 38 
     | 
    
         
            +
                  tables << table_obj.name
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                raise Errno::ENOENT, "Table was not found: '#{table_name}' (#{table_name.class.name}) (tables: #{tables})."
         
     | 
| 
       37 
42 
     | 
    
         
             
              end
         
     | 
| 
       38 
43 
     | 
    
         | 
| 
       39 
44 
     | 
    
         
             
              #Yields the tables of the current database.
         
     | 
| 
         @@ -50,10 +55,10 @@ class Baza::Driver::Mysql::Tables 
     | 
|
| 
       50 
55 
     | 
    
         
             
                    obj = @list.get!(name)
         
     | 
| 
       51 
56 
     | 
    
         | 
| 
       52 
57 
     | 
    
         
             
                    if !obj
         
     | 
| 
       53 
     | 
    
         
            -
                      obj = Baza::Driver::Mysql:: 
     | 
| 
       54 
     | 
    
         
            -
                        : 
     | 
| 
       55 
     | 
    
         
            -
                        : 
     | 
| 
       56 
     | 
    
         
            -
                        : 
     | 
| 
      
 58 
     | 
    
         
            +
                      obj = Baza::Driver::Mysql::Table.new(
         
     | 
| 
      
 59 
     | 
    
         
            +
                        db: @db,
         
     | 
| 
      
 60 
     | 
    
         
            +
                        data: d_tables,
         
     | 
| 
      
 61 
     | 
    
         
            +
                        tables: self
         
     | 
| 
       57 
62 
     | 
    
         
             
                      )
         
     | 
| 
       58 
63 
     | 
    
         
             
                      @list[name] = obj
         
     | 
| 
       59 
64 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -76,7 +81,7 @@ class Baza::Driver::Mysql::Tables 
     | 
|
| 
       76 
81 
     | 
    
         
             
              CREATE_ALLOWED_KEYS = [:columns, :indexes, :temp, :return_sql]
         
     | 
| 
       77 
82 
     | 
    
         
             
              #Creates a new table by the given name and data.
         
     | 
| 
       78 
83 
     | 
    
         
             
              def create(name, data, args = nil)
         
     | 
| 
       79 
     | 
    
         
            -
                raise "No columns was given for '#{name}'." if !data[:columns]  
     | 
| 
      
 84 
     | 
    
         
            +
                raise "No columns was given for '#{name}'." if !data[:columns] || data[:columns].empty?
         
     | 
| 
       80 
85 
     | 
    
         | 
| 
       81 
86 
     | 
    
         
             
                sql = "CREATE"
         
     | 
| 
       82 
87 
     | 
    
         
             
                sql << " TEMPORARY" if data[:temp]
         
     | 
| 
         @@ -84,401 +89,38 @@ class Baza::Driver::Mysql::Tables 
     | 
|
| 
       84 
89 
     | 
    
         | 
| 
       85 
90 
     | 
    
         
             
                first = true
         
     | 
| 
       86 
91 
     | 
    
         
             
                data[:columns].each do |col_data|
         
     | 
| 
       87 
     | 
    
         
            -
                  sql << ", "  
     | 
| 
      
 92 
     | 
    
         
            +
                  sql << ", " unless first
         
     | 
| 
       88 
93 
     | 
    
         
             
                  first = false if first
         
     | 
| 
       89 
94 
     | 
    
         
             
                  col_data.delete(:after) if col_data[:after]
         
     | 
| 
       90 
95 
     | 
    
         
             
                  sql << @db.cols.data_sql(col_data)
         
     | 
| 
       91 
96 
     | 
    
         
             
                end
         
     | 
| 
       92 
97 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
                if data[:indexes]  
     | 
| 
      
 98 
     | 
    
         
            +
                if data[:indexes] && !data[:indexes].empty?
         
     | 
| 
       94 
99 
     | 
    
         
             
                  sql << ", "
         
     | 
| 
       95 
     | 
    
         
            -
                  sql << Baza::Driver::Mysql:: 
     | 
| 
       96 
     | 
    
         
            -
                    : 
     | 
| 
       97 
     | 
    
         
            -
                    : 
     | 
| 
       98 
     | 
    
         
            -
                    : 
     | 
| 
       99 
     | 
    
         
            -
                    : 
     | 
| 
       100 
     | 
    
         
            -
                    : 
     | 
| 
      
 100 
     | 
    
         
            +
                  sql << Baza::Driver::Mysql::Table.create_indexes(data[:indexes], {
         
     | 
| 
      
 101 
     | 
    
         
            +
                    db: @db,
         
     | 
| 
      
 102 
     | 
    
         
            +
                    return_sql: true,
         
     | 
| 
      
 103 
     | 
    
         
            +
                    create: false,
         
     | 
| 
      
 104 
     | 
    
         
            +
                    on_table: false,
         
     | 
| 
      
 105 
     | 
    
         
            +
                    table_name: name
         
     | 
| 
       101 
106 
     | 
    
         
             
                  })
         
     | 
| 
       102 
107 
     | 
    
         
             
                end
         
     | 
| 
       103 
108 
     | 
    
         | 
| 
       104 
109 
     | 
    
         
             
                sql << ")"
         
     | 
| 
       105 
110 
     | 
    
         | 
| 
       106 
     | 
    
         
            -
                return [sql] if args  
     | 
| 
      
 111 
     | 
    
         
            +
                return [sql] if args && args[:return_sql]
         
     | 
| 
       107 
112 
     | 
    
         
             
                @db.query(sql)
         
     | 
| 
       108 
113 
     | 
    
         
             
              end
         
     | 
| 
       109 
114 
     | 
    
         | 
| 
       110 
115 
     | 
    
         
             
              private
         
     | 
| 
       111 
116 
     | 
    
         | 
| 
       112 
117 
     | 
    
         
             
              def add_to_list(table)
         
     | 
| 
       113 
     | 
    
         
            -
                raise "Already exists: '#{table.name}'." if @list.key?(table.name)  
     | 
| 
      
 118 
     | 
    
         
            +
                raise "Already exists: '#{table.name}'." if @list.key?(table.name) && @list[table.name].__id__ != table.__id__
         
     | 
| 
       114 
119 
     | 
    
         
             
                @list[table.name] = table
         
     | 
| 
       115 
120 
     | 
    
         
             
              end
         
     | 
| 
       116 
121 
     | 
    
         | 
| 
       117 
122 
     | 
    
         
             
              def remove_from_list(table)
         
     | 
| 
       118 
     | 
    
         
            -
                raise "Table not in list: '#{table.name}'."  
     | 
| 
      
 123 
     | 
    
         
            +
                raise "Table not in list: '#{table.name}'." unless @list.key?(table.name)
         
     | 
| 
       119 
124 
     | 
    
         
             
                @list.delete(table.name)
         
     | 
| 
       120 
125 
     | 
    
         
             
              end
         
     | 
| 
       121 
126 
     | 
    
         
             
            end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
            class Baza::Driver::Mysql::Tables::Table
         
     | 
| 
       124 
     | 
    
         
            -
              attr_reader :list, :name
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
              def initialize(args)
         
     | 
| 
       127 
     | 
    
         
            -
                @args = args
         
     | 
| 
       128 
     | 
    
         
            -
                @db = args[:db]
         
     | 
| 
       129 
     | 
    
         
            -
                @data = args[:data]
         
     | 
| 
       130 
     | 
    
         
            -
                @subtype = @db.opts[:subtype]
         
     | 
| 
       131 
     | 
    
         
            -
                @list = Wref_map.new
         
     | 
| 
       132 
     | 
    
         
            -
                @indexes_list = Wref_map.new
         
     | 
| 
       133 
     | 
    
         
            -
                @name = @data[:Name].to_sym
         
     | 
| 
       134 
     | 
    
         
            -
                @tables = args[:tables]
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                raise "Could not figure out name from: '#{@data}'." if @data[:Name].to_s.strip.length <= 0
         
     | 
| 
       137 
     | 
    
         
            -
              end
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
              def reload
         
     | 
| 
       140 
     | 
    
         
            -
                @data = @db.q("SHOW TABLE STATUS WHERE `Name` = '#{@db.esc(self.name)}'").fetch
         
     | 
| 
       141 
     | 
    
         
            -
              end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
              #Used to validate in Knj::Wrap_map.
         
     | 
| 
       144 
     | 
    
         
            -
              def __object_unique_id__
         
     | 
| 
       145 
     | 
    
         
            -
                return @data[:Name]
         
     | 
| 
       146 
     | 
    
         
            -
              end
         
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
              def drop
         
     | 
| 
       149 
     | 
    
         
            -
                raise "Cant drop native table: '#{self.name}'." if self.native?
         
     | 
| 
       150 
     | 
    
         
            -
                @db.query("DROP TABLE `#{@db.esc_table(self.name)}`")
         
     | 
| 
       151 
     | 
    
         
            -
                @tables.__send__(:remove_from_list, self)
         
     | 
| 
       152 
     | 
    
         
            -
                return nil
         
     | 
| 
       153 
     | 
    
         
            -
              end
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
              #Returns true if the table is safe to drop.
         
     | 
| 
       156 
     | 
    
         
            -
              def native?
         
     | 
| 
       157 
     | 
    
         
            -
                return true if @db.q("SELECT DATABASE() AS db").fetch[:db] == "mysql"
         
     | 
| 
       158 
     | 
    
         
            -
                return false
         
     | 
| 
       159 
     | 
    
         
            -
              end
         
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
              def optimize
         
     | 
| 
       162 
     | 
    
         
            -
                @db.query("OPTIMIZE TABLE `#{@db.esc_table(self.name)}`")
         
     | 
| 
       163 
     | 
    
         
            -
                return self
         
     | 
| 
       164 
     | 
    
         
            -
              end
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
              def rows_count
         
     | 
| 
       167 
     | 
    
         
            -
                return @db.q("SELECT COUNT(*) AS count FROM `#{@db.esc_table(self.name)}`").fetch[:count].to_i
         
     | 
| 
       168 
     | 
    
         
            -
              end
         
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
              def column(name)
         
     | 
| 
       171 
     | 
    
         
            -
                name = name.to_sym
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
                if col = @list.get!(name)
         
     | 
| 
       174 
     | 
    
         
            -
                  return @list[name]
         
     | 
| 
       175 
     | 
    
         
            -
                end
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                self.columns(:name => name) do |col|
         
     | 
| 
       178 
     | 
    
         
            -
                  return col if col.name == name
         
     | 
| 
       179 
     | 
    
         
            -
                end
         
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
                raise Errno::ENOENT, "Column not found: '#{name}'."
         
     | 
| 
       182 
     | 
    
         
            -
              end
         
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
              def columns(args = nil)
         
     | 
| 
       185 
     | 
    
         
            -
                @db.cols
         
     | 
| 
       186 
     | 
    
         
            -
                ret = {}
         
     | 
| 
       187 
     | 
    
         
            -
                sql = "SHOW FULL COLUMNS FROM `#{@db.esc_table(self.name)}`"
         
     | 
| 
       188 
     | 
    
         
            -
                sql << " WHERE `Field` = '#{@db.esc(args[:name])}'" if args and args.key?(:name)
         
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
                @db.q(sql) do |d_cols|
         
     | 
| 
       191 
     | 
    
         
            -
                  name = d_cols[:Field].to_sym
         
     | 
| 
       192 
     | 
    
         
            -
                  obj = @list.get!(name)
         
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
                  if !obj
         
     | 
| 
       195 
     | 
    
         
            -
                    obj = Baza::Driver::Mysql::Columns::Column.new(
         
     | 
| 
       196 
     | 
    
         
            -
                      :table_name => self.name,
         
     | 
| 
       197 
     | 
    
         
            -
                      :db => @db,
         
     | 
| 
       198 
     | 
    
         
            -
                      :data => d_cols
         
     | 
| 
       199 
     | 
    
         
            -
                    )
         
     | 
| 
       200 
     | 
    
         
            -
                    @list[name] = obj
         
     | 
| 
       201 
     | 
    
         
            -
                  end
         
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
                  if block_given?
         
     | 
| 
       204 
     | 
    
         
            -
                    yield(obj)
         
     | 
| 
       205 
     | 
    
         
            -
                  else
         
     | 
| 
       206 
     | 
    
         
            -
                    ret[name] = obj
         
     | 
| 
       207 
     | 
    
         
            -
                  end
         
     | 
| 
       208 
     | 
    
         
            -
                end
         
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
                if block_given?
         
     | 
| 
       211 
     | 
    
         
            -
                  return nil
         
     | 
| 
       212 
     | 
    
         
            -
                else
         
     | 
| 
       213 
     | 
    
         
            -
                  return ret
         
     | 
| 
       214 
     | 
    
         
            -
                end
         
     | 
| 
       215 
     | 
    
         
            -
              end
         
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
              def indexes args = nil
         
     | 
| 
       218 
     | 
    
         
            -
                @db.indexes
         
     | 
| 
       219 
     | 
    
         
            -
                ret = {}
         
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
                sql = "SHOW INDEX FROM `#{@db.esc_table(name)}`"
         
     | 
| 
       222 
     | 
    
         
            -
                sql << " WHERE `Key_name` = '#{@db.esc(args[:name])}'" if args && args.key?(:name)
         
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
                @db.q(sql) do |d_indexes|
         
     | 
| 
       225 
     | 
    
         
            -
                  next if d_indexes[:Key_name] == "PRIMARY"
         
     | 
| 
       226 
     | 
    
         
            -
                  obj = @indexes_list.get!(d_indexes[:Key_name].to_s)
         
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
                  unless obj
         
     | 
| 
       229 
     | 
    
         
            -
                    obj = Baza::Driver::Mysql::Indexes::Index.new(
         
     | 
| 
       230 
     | 
    
         
            -
                      table_name: name,
         
     | 
| 
       231 
     | 
    
         
            -
                      db: @db,
         
     | 
| 
       232 
     | 
    
         
            -
                      data: d_indexes
         
     | 
| 
       233 
     | 
    
         
            -
                    )
         
     | 
| 
       234 
     | 
    
         
            -
                    obj.columns << d_indexes[:Column_name]
         
     | 
| 
       235 
     | 
    
         
            -
                    @indexes_list[d_indexes[:Key_name].to_s] = obj
         
     | 
| 
       236 
     | 
    
         
            -
                  end
         
     | 
| 
       237 
     | 
    
         
            -
             
     | 
| 
       238 
     | 
    
         
            -
                  if block_given?
         
     | 
| 
       239 
     | 
    
         
            -
                    yield obj
         
     | 
| 
       240 
     | 
    
         
            -
                  else
         
     | 
| 
       241 
     | 
    
         
            -
                    ret[d_indexes[:Key_name].to_s] = obj
         
     | 
| 
       242 
     | 
    
         
            -
                  end
         
     | 
| 
       243 
     | 
    
         
            -
                end
         
     | 
| 
       244 
     | 
    
         
            -
             
     | 
| 
       245 
     | 
    
         
            -
                if block_given?
         
     | 
| 
       246 
     | 
    
         
            -
                  return nil
         
     | 
| 
       247 
     | 
    
         
            -
                else
         
     | 
| 
       248 
     | 
    
         
            -
                  return ret
         
     | 
| 
       249 
     | 
    
         
            -
                end
         
     | 
| 
       250 
     | 
    
         
            -
              end
         
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
              def index(name)
         
     | 
| 
       253 
     | 
    
         
            -
                name = name.to_s
         
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
                if index = @indexes_list.get!(name)
         
     | 
| 
       256 
     | 
    
         
            -
                  return index
         
     | 
| 
       257 
     | 
    
         
            -
                end
         
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
                self.indexes(:name => name) do |index|
         
     | 
| 
       260 
     | 
    
         
            -
                  return index if index.name.to_s == name
         
     | 
| 
       261 
     | 
    
         
            -
                end
         
     | 
| 
       262 
     | 
    
         
            -
             
     | 
| 
       263 
     | 
    
         
            -
                raise Errno::ENOENT, "Index not found: #{name}."
         
     | 
| 
       264 
     | 
    
         
            -
              end
         
     | 
| 
       265 
     | 
    
         
            -
             
     | 
| 
       266 
     | 
    
         
            -
              def create_columns(col_arr)
         
     | 
| 
       267 
     | 
    
         
            -
                @db.transaction do
         
     | 
| 
       268 
     | 
    
         
            -
                  col_arr.each do |col_data|
         
     | 
| 
       269 
     | 
    
         
            -
                    sql = "ALTER TABLE `#{self.name}` ADD COLUMN #{@db.cols.data_sql(col_data)};"
         
     | 
| 
       270 
     | 
    
         
            -
                    @db.query(sql)
         
     | 
| 
       271 
     | 
    
         
            -
                  end
         
     | 
| 
       272 
     | 
    
         
            -
                end
         
     | 
| 
       273 
     | 
    
         
            -
              end
         
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
              def create_indexes(index_arr, args = {})
         
     | 
| 
       276 
     | 
    
         
            -
                return Baza::Driver::Mysql::Tables::Table.create_indexes(index_arr, args.merge(:table_name => self.name, :db => @db))
         
     | 
| 
       277 
     | 
    
         
            -
              end
         
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
              def self.create_indexes(index_arr, args = {})
         
     | 
| 
       280 
     | 
    
         
            -
                db = args[:db]
         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
                if args[:return_sql]
         
     | 
| 
       283 
     | 
    
         
            -
                  sql = ""
         
     | 
| 
       284 
     | 
    
         
            -
                  first = true
         
     | 
| 
       285 
     | 
    
         
            -
                end
         
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
                index_arr.each do |index_data|
         
     | 
| 
       288 
     | 
    
         
            -
                  if !args[:return_sql]
         
     | 
| 
       289 
     | 
    
         
            -
                    sql = ""
         
     | 
| 
       290 
     | 
    
         
            -
                  end
         
     | 
| 
       291 
     | 
    
         
            -
             
     | 
| 
       292 
     | 
    
         
            -
                  if args[:create] or !args.key?(:create)
         
     | 
| 
       293 
     | 
    
         
            -
                    sql << "CREATE"
         
     | 
| 
       294 
     | 
    
         
            -
                  end
         
     | 
| 
       295 
     | 
    
         
            -
             
     | 
| 
       296 
     | 
    
         
            -
                  if index_data.is_a?(String) or index_data.is_a?(Symbol)
         
     | 
| 
       297 
     | 
    
         
            -
                    index_data = {:name => index_data, :columns => [index_data]}
         
     | 
| 
       298 
     | 
    
         
            -
                  end
         
     | 
| 
       299 
     | 
    
         
            -
             
     | 
| 
       300 
     | 
    
         
            -
                  raise "No name was given: '#{index_data}'." if !index_data.key?(:name) or index_data[:name].to_s.strip.empty?
         
     | 
| 
       301 
     | 
    
         
            -
                  raise "No columns was given on index: '#{index_data[:name]}'." if !index_data[:columns] or index_data[:columns].empty?
         
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
                  if args[:return_sql]
         
     | 
| 
       304 
     | 
    
         
            -
                    if first
         
     | 
| 
       305 
     | 
    
         
            -
                      first = false
         
     | 
| 
       306 
     | 
    
         
            -
                    else
         
     | 
| 
       307 
     | 
    
         
            -
                      sql << ", "
         
     | 
| 
       308 
     | 
    
         
            -
                    end
         
     | 
| 
       309 
     | 
    
         
            -
                  end
         
     | 
| 
       310 
     | 
    
         
            -
             
     | 
| 
       311 
     | 
    
         
            -
                  sql << " UNIQUE" if index_data[:unique]
         
     | 
| 
       312 
     | 
    
         
            -
                  sql << " INDEX `#{db.esc_col(index_data[:name])}`"
         
     | 
| 
       313 
     | 
    
         
            -
             
     | 
| 
       314 
     | 
    
         
            -
                  if args[:on_table] or !args.key?(:on_table)
         
     | 
| 
       315 
     | 
    
         
            -
                    sql << " ON `#{db.esc_table(args[:table_name])}`"
         
     | 
| 
       316 
     | 
    
         
            -
                  end
         
     | 
| 
       317 
     | 
    
         
            -
             
     | 
| 
       318 
     | 
    
         
            -
                  sql << " ("
         
     | 
| 
       319 
     | 
    
         
            -
             
     | 
| 
       320 
     | 
    
         
            -
                  first = true
         
     | 
| 
       321 
     | 
    
         
            -
                  index_data[:columns].each do |col_name|
         
     | 
| 
       322 
     | 
    
         
            -
                    sql << ", " if !first
         
     | 
| 
       323 
     | 
    
         
            -
                    first = false if first
         
     | 
| 
       324 
     | 
    
         
            -
             
     | 
| 
       325 
     | 
    
         
            -
                    sql << "`#{db.esc_col(col_name)}`"
         
     | 
| 
       326 
     | 
    
         
            -
                  end
         
     | 
| 
       327 
     | 
    
         
            -
             
     | 
| 
       328 
     | 
    
         
            -
                  sql << ")"
         
     | 
| 
       329 
     | 
    
         
            -
             
     | 
| 
       330 
     | 
    
         
            -
                  if !args[:return_sql]
         
     | 
| 
       331 
     | 
    
         
            -
                    db.query(sql)
         
     | 
| 
       332 
     | 
    
         
            -
                  end
         
     | 
| 
       333 
     | 
    
         
            -
                end
         
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
                if args[:return_sql]
         
     | 
| 
       336 
     | 
    
         
            -
                  return sql
         
     | 
| 
       337 
     | 
    
         
            -
                else
         
     | 
| 
       338 
     | 
    
         
            -
                  return nil
         
     | 
| 
       339 
     | 
    
         
            -
                end
         
     | 
| 
       340 
     | 
    
         
            -
              end
         
     | 
| 
       341 
     | 
    
         
            -
             
     | 
| 
       342 
     | 
    
         
            -
              def rename(newname)
         
     | 
| 
       343 
     | 
    
         
            -
                newname = newname.to_sym
         
     | 
| 
       344 
     | 
    
         
            -
                oldname = self.name
         
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
                @tables.__send__(:remove_from_list, self)
         
     | 
| 
       347 
     | 
    
         
            -
                @db.query("ALTER TABLE `#{@db.esc_table(oldname)}` RENAME TO `#{@db.esc_table(newname)}`")
         
     | 
| 
       348 
     | 
    
         
            -
             
     | 
| 
       349 
     | 
    
         
            -
                @data[:Name] = newname
         
     | 
| 
       350 
     | 
    
         
            -
                @name = newname
         
     | 
| 
       351 
     | 
    
         
            -
                @tables.__send__(:add_to_list, self)
         
     | 
| 
       352 
     | 
    
         
            -
             
     | 
| 
       353 
     | 
    
         
            -
                @list.each do |name, column|
         
     | 
| 
       354 
     | 
    
         
            -
                  column.instance_variable_set(:@name, newname)
         
     | 
| 
       355 
     | 
    
         
            -
                  column.args[:Field] = newname
         
     | 
| 
       356 
     | 
    
         
            -
                end
         
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
                @indexes_list.each do |name, index|
         
     | 
| 
       359 
     | 
    
         
            -
                  index.args[:table_name] = newname
         
     | 
| 
       360 
     | 
    
         
            -
                end
         
     | 
| 
       361 
     | 
    
         
            -
              end
         
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
       363 
     | 
    
         
            -
              def truncate
         
     | 
| 
       364 
     | 
    
         
            -
                @db.query("TRUNCATE `#{@db.esc_table(self.name)}`")
         
     | 
| 
       365 
     | 
    
         
            -
                return self
         
     | 
| 
       366 
     | 
    
         
            -
              end
         
     | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
              def data
         
     | 
| 
       369 
     | 
    
         
            -
                ret = {
         
     | 
| 
       370 
     | 
    
         
            -
                  :name => self.name,
         
     | 
| 
       371 
     | 
    
         
            -
                  :columns => [],
         
     | 
| 
       372 
     | 
    
         
            -
                  :indexes => []
         
     | 
| 
       373 
     | 
    
         
            -
                }
         
     | 
| 
       374 
     | 
    
         
            -
             
     | 
| 
       375 
     | 
    
         
            -
                columns.each do |name, column|
         
     | 
| 
       376 
     | 
    
         
            -
                  ret[:columns] << column.data
         
     | 
| 
       377 
     | 
    
         
            -
                end
         
     | 
| 
       378 
     | 
    
         
            -
             
     | 
| 
       379 
     | 
    
         
            -
                indexes.each do |name, index|
         
     | 
| 
       380 
     | 
    
         
            -
                  ret[:indexes] << index.data if name != "PRIMARY"
         
     | 
| 
       381 
     | 
    
         
            -
                end
         
     | 
| 
       382 
     | 
    
         
            -
             
     | 
| 
       383 
     | 
    
         
            -
                return ret
         
     | 
| 
       384 
     | 
    
         
            -
              end
         
     | 
| 
       385 
     | 
    
         
            -
             
     | 
| 
       386 
     | 
    
         
            -
              def insert(data)
         
     | 
| 
       387 
     | 
    
         
            -
                @db.insert(self.name, data)
         
     | 
| 
       388 
     | 
    
         
            -
              end
         
     | 
| 
       389 
     | 
    
         
            -
             
     | 
| 
       390 
     | 
    
         
            -
              def clone(newname, args = {})
         
     | 
| 
       391 
     | 
    
         
            -
                raise "Invalid name." if newname.to_s.strip.empty?
         
     | 
| 
       392 
     | 
    
         
            -
             
     | 
| 
       393 
     | 
    
         
            -
                sql = "CREATE TABLE `#{@db.esc_table(newname)}` ("
         
     | 
| 
       394 
     | 
    
         
            -
                first = true
         
     | 
| 
       395 
     | 
    
         
            -
                pkey_found = false
         
     | 
| 
       396 
     | 
    
         
            -
                pkeys = []
         
     | 
| 
       397 
     | 
    
         
            -
             
     | 
| 
       398 
     | 
    
         
            -
                columns do |col|
         
     | 
| 
       399 
     | 
    
         
            -
                  sql << ", " if !first
         
     | 
| 
       400 
     | 
    
         
            -
                  first = false if first
         
     | 
| 
       401 
     | 
    
         
            -
             
     | 
| 
       402 
     | 
    
         
            -
                  col_data = col.data
         
     | 
| 
       403 
     | 
    
         
            -
                  pkey_found = true if !pkey_found and col_data[:primarykey] and args[:force_single_pkey]
         
     | 
| 
       404 
     | 
    
         
            -
             
     | 
| 
       405 
     | 
    
         
            -
                  if args[:no_pkey] or (pkey_found and col_data[:primarykey] and args[:force_single_pkey])
         
     | 
| 
       406 
     | 
    
         
            -
                    col_data[:primarykey] = false
         
     | 
| 
       407 
     | 
    
         
            -
                  end
         
     | 
| 
       408 
     | 
    
         
            -
             
     | 
| 
       409 
     | 
    
         
            -
                  if col_data[:primarykey]
         
     | 
| 
       410 
     | 
    
         
            -
                    pkeys << col_data[:name]
         
     | 
| 
       411 
     | 
    
         
            -
                    col_data.delete(:primarykey)
         
     | 
| 
       412 
     | 
    
         
            -
                  end
         
     | 
| 
       413 
     | 
    
         
            -
             
     | 
| 
       414 
     | 
    
         
            -
                  if args[:all_cols_storage]
         
     | 
| 
       415 
     | 
    
         
            -
                    col_data[:storage] = args[:all_cols_storage]
         
     | 
| 
       416 
     | 
    
         
            -
                  end
         
     | 
| 
       417 
     | 
    
         
            -
             
     | 
| 
       418 
     | 
    
         
            -
                  sql << @db.cols.data_sql(col_data)
         
     | 
| 
       419 
     | 
    
         
            -
                end
         
     | 
| 
       420 
     | 
    
         
            -
             
     | 
| 
       421 
     | 
    
         
            -
                unless pkeys.empty?
         
     | 
| 
       422 
     | 
    
         
            -
                  sql << ", PRIMARY KEY ("
         
     | 
| 
       423 
     | 
    
         
            -
             
     | 
| 
       424 
     | 
    
         
            -
                  first = true
         
     | 
| 
       425 
     | 
    
         
            -
                  pkeys.each do |pkey|
         
     | 
| 
       426 
     | 
    
         
            -
                    sql << ", " if !first
         
     | 
| 
       427 
     | 
    
         
            -
                    first = false if first
         
     | 
| 
       428 
     | 
    
         
            -
                    sql << "`#{@db.esc_col(pkey)}`"
         
     | 
| 
       429 
     | 
    
         
            -
                  end
         
     | 
| 
       430 
     | 
    
         
            -
             
     | 
| 
       431 
     | 
    
         
            -
                  sql << ")"
         
     | 
| 
       432 
     | 
    
         
            -
                end
         
     | 
| 
       433 
     | 
    
         
            -
             
     | 
| 
       434 
     | 
    
         
            -
                sql << ")"
         
     | 
| 
       435 
     | 
    
         
            -
                sql << " TABLESPACE #{args[:tablespace]}" if args[:tablespace]
         
     | 
| 
       436 
     | 
    
         
            -
                sql << " ENGINE=#{args[:engine]}" if args[:engine]
         
     | 
| 
       437 
     | 
    
         
            -
                sql << ";"
         
     | 
| 
       438 
     | 
    
         
            -
             
     | 
| 
       439 
     | 
    
         
            -
                #Create table.
         
     | 
| 
       440 
     | 
    
         
            -
                @db.query(sql)
         
     | 
| 
       441 
     | 
    
         
            -
             
     | 
| 
       442 
     | 
    
         
            -
             
     | 
| 
       443 
     | 
    
         
            -
                #Insert data of previous data in a single query.
         
     | 
| 
       444 
     | 
    
         
            -
                @db.query("INSERT INTO `#{@db.esc_table(newname)}` SELECT * FROM `#{@db.esc_table(self.name)}`")
         
     | 
| 
       445 
     | 
    
         
            -
             
     | 
| 
       446 
     | 
    
         
            -
             
     | 
| 
       447 
     | 
    
         
            -
                #Create indexes.
         
     | 
| 
       448 
     | 
    
         
            -
                new_table = @db.tables[newname]
         
     | 
| 
       449 
     | 
    
         
            -
                indexes_list = []
         
     | 
| 
       450 
     | 
    
         
            -
                indexes do |index|
         
     | 
| 
       451 
     | 
    
         
            -
                  indexes_list << index.data unless index.primary?
         
     | 
| 
       452 
     | 
    
         
            -
                end
         
     | 
| 
       453 
     | 
    
         
            -
             
     | 
| 
       454 
     | 
    
         
            -
                new_table.create_indexes(indexes_list)
         
     | 
| 
       455 
     | 
    
         
            -
             
     | 
| 
       456 
     | 
    
         
            -
             
     | 
| 
       457 
     | 
    
         
            -
                #Return new table.
         
     | 
| 
       458 
     | 
    
         
            -
                return new_table
         
     | 
| 
       459 
     | 
    
         
            -
              end
         
     | 
| 
       460 
     | 
    
         
            -
             
     | 
| 
       461 
     | 
    
         
            -
              #Returns the current engine of the table.
         
     | 
| 
       462 
     | 
    
         
            -
              def engine
         
     | 
| 
       463 
     | 
    
         
            -
                return @data[:Engine]
         
     | 
| 
       464 
     | 
    
         
            -
              end
         
     | 
| 
       465 
     | 
    
         
            -
             
     | 
| 
       466 
     | 
    
         
            -
              #Changes the engine for a table.
         
     | 
| 
       467 
     | 
    
         
            -
              def engine=(newengine)
         
     | 
| 
       468 
     | 
    
         
            -
                raise "Invalid engine: '#{newengine}'." if !newengine.to_s.match(/^[A-z]+$/)
         
     | 
| 
       469 
     | 
    
         
            -
                @db.query("ALTER TABLE `#{@db.esc_table(self.name)}` ENGINE = #{newengine}") if self.engine.to_s != newengine.to_s
         
     | 
| 
       470 
     | 
    
         
            -
                @data[:Engine] = newengine
         
     | 
| 
       471 
     | 
    
         
            -
              end
         
     | 
| 
       472 
     | 
    
         
            -
             
     | 
| 
       473 
     | 
    
         
            -
              private
         
     | 
| 
       474 
     | 
    
         
            -
             
     | 
| 
       475 
     | 
    
         
            -
              def remove_column_from_list(col)
         
     | 
| 
       476 
     | 
    
         
            -
                raise "Column not found: '#{col.name}'." if !@list.key?(col.name)
         
     | 
| 
       477 
     | 
    
         
            -
                @list.delete(col.name)
         
     | 
| 
       478 
     | 
    
         
            -
              end
         
     | 
| 
       479 
     | 
    
         
            -
             
     | 
| 
       480 
     | 
    
         
            -
              def add_column_to_list(col)
         
     | 
| 
       481 
     | 
    
         
            -
                raise "Column already exists: '#{col.name}'." if @list.key?(col.name)
         
     | 
| 
       482 
     | 
    
         
            -
                @list[col.name] = col
         
     | 
| 
       483 
     | 
    
         
            -
              end
         
     | 
| 
       484 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -2,30 +2,30 @@ class KnjDB_java_sqlite3 
     | 
|
| 
       2 
2 
     | 
    
         
             
              def escape_table
         
     | 
| 
       3 
3 
     | 
    
         
             
                return "`"
         
     | 
| 
       4 
4 
     | 
    
         
             
              end
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       6 
6 
     | 
    
         
             
              def escape_col
         
     | 
| 
       7 
7 
     | 
    
         
             
                return "`"
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       10 
10 
     | 
    
         
             
              def escape_val
         
     | 
| 
       11 
11 
     | 
    
         
             
                return "'"
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       14 
14 
     | 
    
         
             
              def initialize(baza_db_obj)
         
     | 
| 
       15 
15 
     | 
    
         
             
                @baza_db = baza_db_obj
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       17 
17 
     | 
    
         
             
                if @baza_db.opts[:sqlite_driver]
         
     | 
| 
       18 
18 
     | 
    
         
             
                  require @baza_db.opts[:sqlite_driver]
         
     | 
| 
       19 
19 
     | 
    
         
             
                else
         
     | 
| 
       20 
20 
     | 
    
         
             
                  require File.dirname(__FILE__) + "/sqlitejdbc-v056.jar"
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       23 
23 
     | 
    
         
             
                require "java"
         
     | 
| 
       24 
24 
     | 
    
         
             
                import "org.sqlite.JDBC"
         
     | 
| 
       25 
25 
     | 
    
         
             
                @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:" + @baza_db.opts[:path])
         
     | 
| 
       26 
26 
     | 
    
         
             
                @stat = @conn.createStatement
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       29 
29 
     | 
    
         
             
              def query(string)
         
     | 
| 
       30 
30 
     | 
    
         
             
                begin
         
     | 
| 
       31 
31 
     | 
    
         
             
                  return KnjDB_java_sqlite3_result.new(@stat.executeQuery(string))
         
     | 
| 
         @@ -37,21 +37,18 @@ class KnjDB_java_sqlite3 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  end
         
     | 
| 
       38 
38 
     | 
    
         
             
                end
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
       41 
41 
     | 
    
         
             
              def fetch(result)
         
     | 
| 
       42 
42 
     | 
    
         
             
                return result.fetch
         
     | 
| 
       43 
43 
     | 
    
         
             
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       45 
45 
     | 
    
         
             
              def escape(string)
         
     | 
| 
       46 
     | 
    
         
            -
                 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
                
         
     | 
| 
       50 
     | 
    
         
            -
                  string = string.gsub("'", "\\'")
         
     | 
| 
      
 46 
     | 
    
         
            +
                return "" unless string
         
     | 
| 
      
 47 
     | 
    
         
            +
                string = string.gsub("'", "\\'")
         
     | 
| 
       51 
48 
     | 
    
         
             
                return string
         
     | 
| 
       52 
49 
     | 
    
         
             
              end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              def  
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def last_id
         
     | 
| 
       55 
52 
     | 
    
         
             
                return @conn.last_insert_row_id
         
     | 
| 
       56 
53 
     | 
    
         
             
              end
         
     | 
| 
       57 
54 
     | 
    
         
             
            end
         
     | 
| 
         @@ -60,24 +57,22 @@ class KnjDB_java_sqlite3_result 
     | 
|
| 
       60 
57 
     | 
    
         
             
              def initialize(rs)
         
     | 
| 
       61 
58 
     | 
    
         
             
                @rs = rs
         
     | 
| 
       62 
59 
     | 
    
         
             
                @index = 0
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       64 
61 
     | 
    
         
             
                if rs
         
     | 
| 
       65 
62 
     | 
    
         
             
                  @metadata = rs.getMetaData
         
     | 
| 
       66 
63 
     | 
    
         
             
                  @columns_count = @metadata.getColumnCount
         
     | 
| 
       67 
64 
     | 
    
         
             
                end
         
     | 
| 
       68 
65 
     | 
    
         
             
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       70 
67 
     | 
    
         
             
              def fetch
         
     | 
| 
       71 
     | 
    
         
            -
                 
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
                
         
     | 
| 
      
 68 
     | 
    
         
            +
                return false unless @rs.next
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       75 
70 
     | 
    
         
             
                tha_return = {}
         
     | 
| 
       76 
71 
     | 
    
         
             
                for i in (1..@columns_count)
         
     | 
| 
       77 
72 
     | 
    
         
             
                  col_name = @metadata.getColumnName(i)
         
     | 
| 
       78 
73 
     | 
    
         
             
                  tha_return.store(col_name, @rs.getString(i))
         
     | 
| 
       79 
74 
     | 
    
         
             
                end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
       81 
76 
     | 
    
         
             
                return tha_return
         
     | 
| 
       82 
77 
     | 
    
         
             
              end
         
     | 
| 
       83 
78 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,38 +5,38 @@ class Baza::Driver::Sqlite3_ironruby 
     | 
|
| 
       5 
5 
     | 
    
         
             
              def escape_table
         
     | 
| 
       6 
6 
     | 
    
         
             
                return "`"
         
     | 
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       9 
9 
     | 
    
         
             
              def escape_col
         
     | 
| 
       10 
10 
     | 
    
         
             
                return "`"
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
       13 
13 
     | 
    
         
             
              def escape_val
         
     | 
| 
       14 
14 
     | 
    
         
             
                return "'"
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       17 
17 
     | 
    
         
             
              def initialize(baza_db_obj)
         
     | 
| 
       18 
18 
     | 
    
         
             
                @baza_db = baza_db_obj
         
     | 
| 
       19 
19 
     | 
    
         
             
                @conn = Mono::Data::SqliteClient::SqliteConnection.new("URI=file:" + @baza_db.opts[:path] + ",version=3")
         
     | 
| 
       20 
20 
     | 
    
         
             
                @conn.Open
         
     | 
| 
       21 
21 
     | 
    
         
             
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       23 
23 
     | 
    
         
             
              def query(string)
         
     | 
| 
       24 
24 
     | 
    
         
             
                dbcmd = @conn.CreateCommand
         
     | 
| 
       25 
25 
     | 
    
         
             
                dbcmd.CommandText = string
         
     | 
| 
       26 
26 
     | 
    
         
             
                reader = dbcmd.ExecuteReader
         
     | 
| 
       27 
27 
     | 
    
         
             
                return Baza::Driver::Sqlite3_ironruby_result.new(reader)
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
       30 
30 
     | 
    
         
             
              def escape(string)
         
     | 
| 
       31 
31 
     | 
    
         
             
                if (!string)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  return ""
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       35 
35 
     | 
    
         
             
                  string = string.gsub("'", "\\'")
         
     | 
| 
       36 
36 
     | 
    
         
             
                return string
         
     | 
| 
       37 
37 
     | 
    
         
             
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              def  
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def last_id
         
     | 
| 
       40 
40 
     | 
    
         
             
                return @conn.last_insert_row_id
         
     | 
| 
       41 
41 
     | 
    
         
             
              end
         
     | 
| 
       42 
42 
     | 
    
         
             
            end
         
     | 
| 
         @@ -45,14 +45,14 @@ class Baza::Driver::Sqlite3_ironruby_result 
     | 
|
| 
       45 
45 
     | 
    
         
             
              def initialize(reader)
         
     | 
| 
       46 
46 
     | 
    
         
             
                @reader = reader
         
     | 
| 
       47 
47 
     | 
    
         
             
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       49 
49 
     | 
    
         
             
              def fetch
         
     | 
| 
       50 
50 
     | 
    
         
             
                if !@reader.Read
         
     | 
| 
       51 
51 
     | 
    
         
             
                  return false
         
     | 
| 
       52 
52 
     | 
    
         
             
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       54 
54 
     | 
    
         
             
                ret = {}
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       56 
56 
     | 
    
         
             
                count = 0
         
     | 
| 
       57 
57 
     | 
    
         
             
                while true
         
     | 
| 
       58 
58 
     | 
    
         
             
                  begin
         
     | 
| 
         @@ -60,10 +60,10 @@ class Baza::Driver::Sqlite3_ironruby_result 
     | 
|
| 
       60 
60 
     | 
    
         
             
                  rescue IndexError => e
         
     | 
| 
       61 
61 
     | 
    
         
             
                    break
         
     | 
| 
       62 
62 
     | 
    
         
             
                  end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       64 
64 
     | 
    
         
             
                  count += 1
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       67 
67 
     | 
    
         
             
                return ret
         
     | 
| 
       68 
68 
     | 
    
         
             
              end
         
     | 
| 
       69 
69 
     | 
    
         
             
            end
         
     |