Guest User

Untitled

a guest
May 24th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. require 'rubygems'
  2. require 'fb'
  3. include Fb
  4. # The Database class acts as a factory for Connections.
  5. # It can also create and drop databases.
  6. db = Database.new(
  7. :database => "localhost:/tmp/readme.fdb",
  8. :username => 'sysdba',
  9. :password => 'masterkey')
  10. # :database is the only parameter without a default.
  11. # Let's connect to the database, creating it if it doesn't already exist.
  12. conn = db.connect rescue db.create.connect
  13. # We'll need to create the database schema if this is a new database.
  14. conn.execute("CREATE TABLE TEST (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(20))") if !conn.table_names.include?("TEST")
  15. # Let's insert some test data using a parameterized query. Note the use of question marks for place holders.
  16. 10.times {|id| conn.execute("INSERT INTO TEST VALUES (?, ?)", id, "John #{id}") }
  17. # Here we'll conduct a spot check of the data we have just inserted.
  18. ary = conn.query("SELECT * FROM TEST WHERE ID = 0 OR ID = 9")
  19. ary.each {|row| puts "ID: #{row[0]}, Name: #{row[1]}" }
Add Comment
Please, Sign In to add comment