Class: MysqlIsolatedServer::WrappedJDBCConnection
- Inherits:
-
Object
- Object
- MysqlIsolatedServer::WrappedJDBCConnection
- Defined in:
- lib/mysql_isolated_server/jdbc_connection.rb
Instance Method Summary collapse
- #escape(str) ⇒ Object
-
#initialize(port) ⇒ WrappedJDBCConnection
constructor
A new instance of WrappedJDBCConnection.
- #query(sql) ⇒ Object
Constructor Details
#initialize(port) ⇒ WrappedJDBCConnection
Returns a new instance of WrappedJDBCConnection.
7 8 9 |
# File 'lib/mysql_isolated_server/jdbc_connection.rb', line 7 def initialize(port) @cx ||= DriverManager.get_connection("jdbc:mysql://127.0.0.1:#{port}/mysql", "root", "") end |
Instance Method Details
#escape(str) ⇒ Object
40 41 42 |
# File 'lib/mysql_isolated_server/jdbc_connection.rb', line 40 def escape(str) StringEscapeUtils.escapeSql(str) end |
#query(sql) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mysql_isolated_server/jdbc_connection.rb', line 11 def query(sql) stmt = @cx.create_statement if sql !~ /^select/i && sql !~ /^show/i return stmt.execute(sql) end rs = stmt.execute_query(sql) rows = [] while (rs.next) = rs. num_cols = .get_column_count row = {} 1.upto(num_cols) do |col| col_name = .get_column_label(col) col_value = rs.get_object(col) # of meta_data.get_column_type(col) row[col_name] = col_value end rows << row end rows ensure stmt.close if stmt rs.close if rs end |