Datagrid and Database QUery Builder

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Datagrid and Database QUery Builder

Post by bsouthuk » Fri Sep 03, 2010 11:59 am

Hi

I'm building a CRM system in Rev Enterprise and for some reason I cant get Database Query to work when I have a datagrid in my stack. I use the datagrid to pull information from my mySQL database using the following script:

Code: Select all

on mouseUp   
   ## Connect to the database
   put "mysql" into theDBType
   put "MyDatabase" into theDBHost
   put "MyDatabase" into theDBName
   put "MyDatabase" into theDBUser
   put "MyDatabase" into theDBPassword

 put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
   
   if theConnectionID is an integer then
      ## Query the database for data
      put revQueryDatabase( theConnectionID, "select * from Customer") into theCursor
       
      if theCursor is an integer then
         ConvertSQLCursorToArray theCursor, theDataGridArray
         put the result into theError
         
         if theError is empty then
            ## The cursor was successfully converted to an array.
            ## Assign it to the data grid. The 'firstname' and 'lastname' columns
            ## from the database cursor will appear in the matching columns
            ## in the data grid.
            set the dgData of group "DataGrid 1" to theDataGridArray
         end if
         
         ## Close the database cursor 
         revCloseCursor theCursor
      end if
      
      ## Close the database connection
      revCloseDatabase theConnectionID
   else
      answer "Error connecting to the database:" && theConnectionID & "."
   end if
end mouseUp

command ConvertSQLCursorToArray pCursor, @pOutArrayA
   local i,j
   local theFields
   local theError
   
   ## Get the names of all the columns in the database cursor
   put revDatabaseColumnNames(pCursor) into theFields
   if theFields begins with "revdberr," then
      put item 2 to -1 of theFields into theError
   end if
   
   if theError is empty then
      put 0 into i
      ## Loop through all rows in cursor
      repeat until revQueryIsAtEnd(pCursor)
         add 1 to i
         
         ## Move all fields in row into next dimension of the array
         repeat for each item theField in theFields
            put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]
         end repeat
         
         revMoveToNextRecord pCursor
      end repeat
   end if
   
   return theError
end ConvertSQLCursorToArray
However when I try to use Database Query builder, it does not allow me to add a query. I have tried deleting the datagrid then using query builder which works but the when I add a datagrid and using my above code then I cannot connect to my database through Query Builder. I can create substack which works fine but needs to be on the same stack.

Can anyone spot the problem with this?

Post Reply