database connect/query id's

Jan Schenkel janschenkel at yahoo.com
Sat Jun 10 01:24:57 EDT 2006


--- Robert Mann <robmann at gp-racing.com> wrote:
> can some one send me a complete example of how to
> connect to database then
> find the database id number to use in the query,
> then how to find the record
> set id number to use to display the data
> 
> I think these are the four library items that need
> to be used?
> 
> revOpenDatabase
> 
> revDataBaseID
> 
> revQueryDatabase
> 
> revDatabaseCursors
> 
> Thanks for the help
> 
> Robert Mann
> 

Hi Robert,

As Josh already suggested, download a copy of Sarah's
database example stack.
Another good introduction to Revolution and Databases
can be found in the altSQLite demo stack:
<http://www.gadgetplugins.com/altsqlite/SQLite3Demo.rev>

A basic script to connect, extract information and
disocnnect will look something like this:
##
on mouseUp
  -- first connect to the database
  put revOpenDatabase( \
      "mysql", \        -- database type
      "localhost", \    -- database server
      "testdb", \       -- database name
      "user", \         -- user name
      "password", \     -- user password
      "false") \        -- don't use SSL
      into tConnectionID
  -- check the connection
  if tConnectionID is not a number then
    answer error tConnectionID
    exit mouseUp
  end if
  -- now query the database
  put "SELECT * FROM Customers" into tSQLQuery
  put revQueryDatabase( \
      tConnectionID, \  -- the connection
      tSQLQuery) \      -- the query
      into tCursorID
  -- check the cursor (aka the RecordSet)
  if tCursorID is not a number then
    answer error tCursorID
    exit mouseUp
  end if
  -- now do something with the cursor
  -- example: put revDatabaseColumnNames(tCursorID)
  -- ...
  -- finally clean up everything
  revCloseCursor tCursorID
  revCloseDatabase tConnectionID
end mouseUp
##

You may want to save the connection ID in a hlobal
variable, rather than connect to the database every
time you want to query it.

Hope this gets you started,

Jan Schenkel.

Quartam Reports for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the use-livecode mailing list