SQL unable to get query results, HELP!
Posted: Fri Aug 03, 2012 5:30 am
I am writing an application for my brothers company. Here is what I am trying to accomplish:
Access an SQL database hosted on a remote server. Lookup a unique code and return several fields of data back to the user. The code is for a mail piece sent to prospective customers and the data returned verifies who the mailing went to.
I have a single card in my application, that card displays the fields of data and allows the input of the mail piece code and a search button. I have made what is reported as a valid connection to the database and received a connection ID. Then I execute the query and finally look to put the data into the respective fields to be displayed.
I am looking for the database experts to help look at my code to see what I am doing wrong here. I really appreciate your feedback. I have put some XXXXXX in database name, username and password in the code below to mask that information. There are also some parts inserted to verify connection made, record found, etc. I plan to remove these from final code as this should be invisible to the users.
I get the message that the database connection is good. I get the message that the record was found. However I am not getting the data to display...
Here is the code:
global gMCode, gConnectionID, sRecordSetID
on mouseUp
put ID_Field into gMCode
OpenDB
end mouseUp
on OpenDB
-- ## Connect to Database
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "xxxxxxxxxx.hostedresource" into tDatabaseAddress
put "xxxxxxxxxx" into tDatabaseName
put "xxxxxxxxxx" into tDatabaseUser
put "xxxxxxxxxx" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
-- check if it worked and display an error message if it didn't
-- & set the connection ID global
if tResult is a number then
put tResult into gConnectionID
answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
SearchDB
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end OpenDB
On SearchDB
put revQueryDatabase(gConnectionID, "SELECT * from BFFMail where 'MailCode' like ':1'", "gMCode") into sRecordSetID
if sRecordSetID is a number then
answer info "record found"
DisplayRecord
else
answer info "No Record Found: " & cr & sRecordSetID
end if
end SearchDB
On DisplayRecord
put RevDatabaseColumnNamed (sRecordSetID, "LastName") into field "LName_Field"
put RevDatabaseColumnNamed (sRecordSetID, "FirstName") into field "FName_Field"
put RevDatabaseColumnNamed (sRecordSetID, "City") into field "City_Field"
put RevDatabaseColumnNamed (sRecordSetID, "State") into field "State_Field"
end DisplayRecord
Access an SQL database hosted on a remote server. Lookup a unique code and return several fields of data back to the user. The code is for a mail piece sent to prospective customers and the data returned verifies who the mailing went to.
I have a single card in my application, that card displays the fields of data and allows the input of the mail piece code and a search button. I have made what is reported as a valid connection to the database and received a connection ID. Then I execute the query and finally look to put the data into the respective fields to be displayed.
I am looking for the database experts to help look at my code to see what I am doing wrong here. I really appreciate your feedback. I have put some XXXXXX in database name, username and password in the code below to mask that information. There are also some parts inserted to verify connection made, record found, etc. I plan to remove these from final code as this should be invisible to the users.
I get the message that the database connection is good. I get the message that the record was found. However I am not getting the data to display...
Here is the code:
global gMCode, gConnectionID, sRecordSetID
on mouseUp
put ID_Field into gMCode
OpenDB
end mouseUp
on OpenDB
-- ## Connect to Database
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "xxxxxxxxxx.hostedresource" into tDatabaseAddress
put "xxxxxxxxxx" into tDatabaseName
put "xxxxxxxxxx" into tDatabaseUser
put "xxxxxxxxxx" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
-- check if it worked and display an error message if it didn't
-- & set the connection ID global
if tResult is a number then
put tResult into gConnectionID
answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
SearchDB
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end OpenDB
On SearchDB
put revQueryDatabase(gConnectionID, "SELECT * from BFFMail where 'MailCode' like ':1'", "gMCode") into sRecordSetID
if sRecordSetID is a number then
answer info "record found"
DisplayRecord
else
answer info "No Record Found: " & cr & sRecordSetID
end if
end SearchDB
On DisplayRecord
put RevDatabaseColumnNamed (sRecordSetID, "LastName") into field "LName_Field"
put RevDatabaseColumnNamed (sRecordSetID, "FirstName") into field "FName_Field"
put RevDatabaseColumnNamed (sRecordSetID, "City") into field "City_Field"
put RevDatabaseColumnNamed (sRecordSetID, "State") into field "State_Field"
end DisplayRecord