Page 1 of 1

Datagrid Form - MySQL - BLOB

Posted: Thu Feb 12, 2015 6:54 am
by davemustang2015
Hi all,

In my database i have columns with Varchars and one for picture in BLOB.

I am experiencing an issue to loop through the datagrid array so that it is displayed in a datagrid form!

Below is my code for the "populate button" that will be used to populate the "datagrid form".

Code: Select all

command uiPopulatePeople
 
   ## Connect to the database
   put "mysql" into theDBType
   put "127.0.0.1:3306" into theDBHost
   put "wisdom" into theDBName
   put "root" into theDBUser
   put "root" into theDBPassword
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
   
   if theConnectionID is an integer then
      ## Query the database for data
      put "SELECT * FROM admin" into tQuery
      put revQueryDatabase( theConnectionID, tQuery, "tIndex") into theCursor
      if theCursor is not empty then
         
         //take the image from the Query result
         put revDatabaseColumnNamed(theCursor, "picture", "tImageData") into tErrorMsg
         //Show the image in the imageBox

      else
         answer "Error Cursor: Reading from DB"
      end if
      //Close the Cursor with Query Result
      revCloseCursor theCursor
   else
      answer "Error connecting to the database:" && theConnectionID & "."
   end if
   //Close the DB Connection ID
   revCloseDatabase theConnectionID
     
------------------------------------------------------ I want to loop in this section--- HELP

    put "Lucky" into theDataA[1]["FirstName"]
    put "Day" into theDataA[1]["LastName"]
    put "Three Amigo" into theDataA[1]["Title"]
    put tImageData into theDataA[1]["Image URL"]
     
-----------------------------------------------------


    lock screen
    set the dgData of group "DataGrid 1" to theDataA
     
    ## Hilite first row
    set the dgHilitedLines of group "DataGrid 1" to 1
    unlock screen
end uiPopulatePeople

Please your help would be much appreciated

Re: Datagrid Form - MySQL - BLOB

Posted: Sat Feb 14, 2015 2:13 am
by sritcp
I think you should consider using the following commands/functions in the loop (see dictionary):
revMoveToFirstRecord
revMoveToNextRecord
revQueryIsAtEnd

Regards,
Sri.

Re: Datagrid Form - MySQL - BLOB

Posted: Sun Feb 15, 2015 12:20 am
by phaworth
Don't use revDataFromQuery if you are selecting BLOB data.

Use revQueryDatabase to create a cursor. The skeleton code is

put revQueryDatabase(sDBID,tSelect) into tCursor
revMoveToFirstRecord tCursor
repeat revNumberOfRecords(tCursor) times
repeat for each word rColumn in "<list of column names here>"
put revDatabaseColumnNamed(tCursor,rColumn) into <wherever>
end repeat
revMoveToNextRecord tCursor
end repeat

Alternatively, you can use revDataFromQuery to get all the columns except the BLOB column and then use revQueryDatabase to handle just the BLOB column.

Re: Datagrid Form - MySQL - BLOB

Posted: Mon Feb 16, 2015 8:00 am
by davemustang2015
Thanks for your responses, will try your solutions!