Sha256: d651b22c9d5ea833a08f3128d8e1fa97663de1b1b6ab10e19d322643529bd894

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

class Upsert
  # @private
  module SQLite3_Database
    def chunk
      return if buffer.empty?
      row = buffer.shift
      %{INSERT OR IGNORE INTO "#{table_name}" (#{row.columns_sql}) VALUES (#{row.values_sql});UPDATE "#{table_name}" SET #{row.set_sql} WHERE #{row.where_sql}}
    end

    def execute(sql)
      connection.execute_batch sql
    end

    def quote_string(v)
      SINGLE_QUOTE + SQLite3::Database.quote(v) + SINGLE_QUOTE
    end

    def quote_binary(v)
      X_AND_SINGLE_QUOTE + v.unpack("H*")[0] + SINGLE_QUOTE
    end

    def quote_time(v)
      quote_string [v.strftime(ISO8601_DATETIME), sprintf(USEC_SPRINTF, v.usec)].join('.')
    end
    
    def quote_ident(k)
      DOUBLE_QUOTE + SQLite3::Database.quote(k.to_s) + DOUBLE_QUOTE
    end

    def quote_boolean(v)
      s = v ? 't' : 'f'
      quote_string s
    end

    def quote_big_decimal(v)
      v.to_f
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
upsert-0.3.2 lib/upsert/sqlite3_database.rb
upsert-0.3.1 lib/upsert/sqlite3_database.rb
upsert-0.3.0 lib/upsert/sqlite3_database.rb