Datagrid Form - MySQL - BLOB

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
davemustang2015
Posts: 2
Joined: Wed Sep 24, 2014 6:47 pm

Datagrid Form - MySQL - BLOB

Post by davemustang2015 » Thu Feb 12, 2015 6:54 am

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

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Datagrid Form - MySQL - BLOB

Post by sritcp » Sat Feb 14, 2015 2:13 am

I think you should consider using the following commands/functions in the loop (see dictionary):
revMoveToFirstRecord
revMoveToNextRecord
revQueryIsAtEnd

Regards,
Sri.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Datagrid Form - MySQL - BLOB

Post by phaworth » Sun Feb 15, 2015 12:20 am

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.

davemustang2015
Posts: 2
Joined: Wed Sep 24, 2014 6:47 pm

Re: Datagrid Form - MySQL - BLOB

Post by davemustang2015 » Mon Feb 16, 2015 8:00 am

Thanks for your responses, will try your solutions!

Post Reply