-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_retrieval.rb
39 lines (28 loc) · 928 Bytes
/
db_retrieval.rb
1
2
3
4
5
6
7
8
9
10
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
require "rubygems"
require "sinatra"
require "sequel"
begin
# connect to the MySQL server
#dbh = Mysql.real_connect("localhost", "user", "user123", "test")
DB = Sequel.connect(:adapter=>'mysql', :host=>'localhost', :database=>'test', :user=>'user', :password=>'user123')
#DB=Sequel.connect("jdbc:mysql://localhost/test?user=user&password=user123")
# create an student table
DB.create_table :student1 do
primary_key :id
String :name
Float :marks
end
# create a dataset from the items table
student = DB[:student1]
# populate the table
student.insert(:name => 'abc', :marks => rand * 100)
student.insert(:name => 'def', :marks => rand * 100)
student.insert(:name => 'ghi', :marks => rand * 100)
# print out the number of records
puts "Item count: #{student.count}"
get '/student/:id1' do
@p=params[:id1]
st=student.where(:id.like(@p))
"marks = #{st.get(:marks)}"
end
end