Class: FluidDb2::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fluiddb2.rb

Overview

Base

Direct Known Subclasses

Firebird, Mock, Mysql, Mysql2, Pgsql, SQLite, TinyTds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Base

Constructor.

Parameters:

  • uri (String)

    a location for the resource to which we will attach, eg mysql://user:[email protected]/foo



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/fluiddb2.rb', line 125

def initialize(uri)
  if uri.is_a? String
    @uri = URI.parse(uri)
  else
    @uri = uri
  end

  connect

  @verbose = !ENV['VERBOSE'].nil?
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



119
120
121
# File 'lib/fluiddb2.rb', line 119

def connection
  @connection
end

#verbose=(value) ⇒ Object (writeonly)

Sets the attribute verbose

Parameters:

  • value

    the value to set the attribute verbose to.



118
119
120
# File 'lib/fluiddb2.rb', line 118

def verbose=(value)
  @verbose = value
end

Instance Method Details

#beginObject

Transaction Semantics



194
195
196
# File 'lib/fluiddb2.rb', line 194

def begin
  @connection.execute('BEGIN')
end

#closeObject



145
146
147
# File 'lib/fluiddb2.rb', line 145

def close
  fail NotImplementedError, "You must implement 'close'."
end

#commitObject

Transaction Semantics



199
200
201
# File 'lib/fluiddb2.rb', line 199

def commit
  @connection.execute('COMMIT', [])
end

#connectObject



141
142
143
# File 'lib/fluiddb2.rb', line 141

def connect
  fail NotImplementedError, "You must implement 'connect'."
end

#execute(_sql, _params, _expected_affected_rows) ⇒ Object

Execute an insert, update or delete, then check the impact that statement

has on the data.

Parameters:

  • sql (String)

    The SELECT statement to run

  • parama (Array)

    The parameters to be added to the sql query. Ruby types are used to determine formatting and escaping.

  • expected_affected_rows (String)

    The number of rows that should have been updated.



189
190
191
# File 'lib/fluiddb2.rb', line 189

def execute(_sql, _params, _expected_affected_rows)
  fail NotImplementedError, "You must implement 'execute'."
end

#query_for_array(_sql, _params) ⇒ Object

Return a single row from the database, given the sql parameter. Throws an error for no data. Throws an error for more than 1 row

Parameters:

  • sql (String)

    The SELECT statement to run

  • parama (Array)

    The parameters to be added to the sql query. Ruby types are used to determine formatting and escaping.



161
162
163
# File 'lib/fluiddb2.rb', line 161

def query_for_array(_sql, _params)
  fail NotImplementedError, "You must implement 'queryForArray'."
end

#query_for_resultset(_sql, _params) ⇒ Object



177
178
179
# File 'lib/fluiddb2.rb', line 177

def query_for_resultset(_sql, _params)
  fail NotImplementedError, "You must implement 'queryForResultset'."
end

#query_for_value(_sql, _params) ⇒ Object

Return a single value is returned from a single row from the database,

given the sql parameter.

Throws an error for no data. Throws an error for more than 1 row

Parameters:

  • sql (String)

    The SELECT statement to run

  • parama (Array)

    The parameters to be added to the sql query. Ruby types are used to determine formatting and escaping.



173
174
175
# File 'lib/fluiddb2.rb', line 173

def query_for_value(_sql, _params)
  fail NotImplementedError, "You must implement 'queryForValue'."
end

#reconnectObject



149
150
151
152
# File 'lib/fluiddb2.rb', line 149

def reconnect
  close
  connect
end

#rollbackObject

Transaction Semantics



204
205
206
# File 'lib/fluiddb2.rb', line 204

def rollback
  @connection.execute('ROLLBACK', [])
end

#verbose_log(string) ⇒ Object



137
138
139
# File 'lib/fluiddb2.rb', line 137

def verbose_log(string)
  puts string if @verbose == true
end