How can i Navigate to the record of Mysql dataBase?

This is the place to post technical queries about SQL Yoga

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 882
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

How can i Navigate to the record of Mysql dataBase?

Post by trevordevore » Fri Oct 11, 2013 2:36 pm

[This post is an archive from the old SQL Yoga forums]

Hi,

I am learning SQL Yoga, and it is a real pleasure.

Actualy i am testing a simple application like adress book (only one table).

I can connected to my database

Populate a datagrid and display data into fields when i select a row from my datagrid

Retrieve data with elementary search...

My application looks like this:

Field : Socit摲

field : adresse

Field : ID

field: Acteur .... etc

Navigate Buttons : < and >

Create data button : + delete data button: -

Now i would like navigate in my database and display data into fields when i click on navigate Buttons : < or >.

I read the sql Yoga documentation about

"command sqlquery_moveToFirstRecord @pQuery" but i don't understand.

Every body Can explain me the right way to do that?

After that i can use the script below

The Handler to display the data into fields when i select a row of my Datagrid :

script on group "dataGrid 3" is

Code: Select all

--> all handlers

global theRecordAShow

on selectionChanged pHilitedIndex, PrevHilitedIndex

put the dgDataOfIndex[pHilitedIndex] of group "datagrid 3" into theRecordAShow

showRecord theRecordAShow

--uiViewRecord

end selectionChanged

script into card is:

on showRecord theRecordA

put printKeys(TheRecordA)

put theRecordA[ "cl_Societe"] into field "cl_Societe"

Put theRecordA["cl_Activite"] into field "cl_Activite"

put theRecordA["cl_Adresse_complete"] into field "cl_Adresse_complete"

put theRecordA["cl_CP"] into field "cl_CP"

...... etc

end showRecord
Thank you
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 882
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How can i Navigate to the record of Mysql dataBase?

Post by trevordevore » Fri Oct 11, 2013 2:36 pm

hello Trevor,

I don't find how can i "set properties of object" for use sqlquery_moveToNextRecord

i get this error : stack "libSQLYoga": execution error at line 1688 (Object: object does not have this property) near "invalid array type for query"

the code of button > (next record) is

Code: Select all

on mouseUp

##

put field "cl_num" into theSocieteID

put sqlquery_createObject("Client_Tab") into theQueryA

sqlquery_set theQueryA , "order by", "cl_num"

sqlquery_set theQueryA, "conditions","cl_Num is :1", theSocieteID

sqlquery_retrieveAsArray theQueryA, theRecordA

put the result into theError

put printkeys(theQueryA)

if theError is empty then

--sqlquery_moveToNextRecord theSocieteID

set the dgData of group "Datagrid 3" to theRecordA

end if

end mouseUp
I retrieve the data and datagrid is populate, but i don't get the next record.

If i put for conditions "cl_num > 1"I retrieve all data.

Tanks for your help
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 882
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How can i Navigate to the record of Mysql dataBase?

Post by trevordevore » Fri Oct 11, 2013 2:37 pm

Eric,

If you use sqlquery_retrieve then SQL Yoga opens a database cursor. You can then use sqlquery_moveToFirstRecord, sqlquery_moveToNextRecord, etc. to navigate the cursor. You would need to call sqlquery_close to close the cursor in this case.

If you use sqlquery_retrieveAsArray/retrieveAsData/retrieveAsRecords then SQL yoga opens and closes the cursor before returning a value.

If you have a data grid that has all of your database records in it then you could probably just grab the record id from the Data Grid and use sqlrecord_find to get the record info as you click the next/previous buttons though.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 882
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How can i Navigate to the record of Mysql dataBase?

Post by trevordevore » Fri Oct 11, 2013 2:38 pm

Trevor,

I be back this week to write good code for sqlquery_moveToFirstRecord. I am in the same level ,without success.

Have you an exemple to use sqlquery_moveToFirstRecord. What are the steps?

1 sqlquery_createObject

2 sqlquery_set with what param? i need grab record ID?

3 sqlquery_retrieveAsArray , maybe is easy than sqlquery_retrieve

4 sqlquery_moveToFirstRecord with what parm?

You write : if i use data grid it could be probably just grab the record ID and use sqlrecord_find . How do i grab teh record ID from data grid. I read and print all lessons about SQL Yoga . But i don't find de good code.

To finish , i use a trial ScreenSteps since one week . Very , very nice Soft. Great

Thank for all helps
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 882
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How can i Navigate to the record of Mysql dataBase?

Post by trevordevore » Fri Oct 11, 2013 2:38 pm

Have you an exemple to use sqlquery_moveToFirstRecord. What are the steps? "
I put together a lesson showing the basics of working with sqlquery_retrieve. sqlquery_retrieveAsArray opens a database cursor, converts the returned rows into an array and then closes the cursor. sqlquery_retrieve just opens the database cursor so you can use it directly. sqlquery_retrieveAsArray is much easier to use so I recommend using it if you can.

How To Use Cursors With a SQL Query Object
How do i grab teh record ID from data grid"
If you are just assigning the array returned by sqlquery_retrieveAsArray directly to the Data Grid then take a look at the To-Do sample application. It has two Data Grids that integrate with SQL Yoga.

This lesson in the To-Do manual has code that populates a list based on a selection in a Data Grid. The code in the lesson accesses the uSelectedProjectID custom property that I defined for the Data Grid. If you look at the script of the "ProjectsPeople" Data Grid you will see how uSelectedProjectID is defined.

Display To-Do Items in the UI

The relevant code in the Data Grid script is:

Code: Select all

GetDataOfIndex(the dgHilitedIndex of me, "id")
You can read up on GetDataOfIndex in the Data Grid API docs:

Data Grid API
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “SQL Yoga”