Wednesday, June 13, 2007

Sql Connection in Ruby

sql connection in Ruby
=================


Define a sql connectivity function:

def connection
#connection details like dsn, uid and password
$dsn = "POS"
$uid = ""
$pwd = ""
$c = ODBC.connect($dsn, $uid, $pwd)
end


def callConnection()
#opening database connection
connection()
end


#Typical login script
def onLoginClick(event)
$username="myUserName"
$password="myPassword"
$sql="select * from loginmaster where username='" + $username + "' and password='" + $password + "'"
#creating a connection object
$dsn = "POS"
$uid = ""
$pwd = ""
$c = ODBC.connect($dsn, $uid, $pwd)

$q=$c.prepare($sql)
$q.execute

if $q.fetch == nil then
#message will only show if you use wxpos - uncomment below if you are using wxwidget
# message_box("Incorrect Login", "Login",OK ICON_INFORMATION, self)

else
close()
end

end





No comments: