Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 19, 2019 7:30 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: MySQL and Linked Lists
PostPosted: Mon Nov 26, 2012 12:32 pm 
Offline
User avatar

Joined: Mon Nov 29, 2010 7:01 pm
Posts: 446
Let's say I have a table called activity and each activity has a field called parentActivity that points to the id of a different activity.

Is there a way to query an entire linked list given a single activity id?

Essentially get the activity's parent activity, and then that activity's parent activity etc...
Until either it either reaches an ID it has already encountered (which should never happen but we need this to stop infinite loops)
Or it reaches an activity without a parentId.


Top
 Profile  
Reply with quote  
 Post subject: Re: MySQL and Linked Lists
PostPosted: Mon Nov 26, 2012 1:06 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
best I can think it would take a stored procedure with a database cursor.
I know this can be done in Oracle PL/SQL.... but not sure if/how to replicate in mySQL

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: MySQL and Linked Lists
PostPosted: Tue Nov 27, 2012 1:31 am 
Offline

Joined: Tue Feb 06, 2007 11:34 pm
Posts: 192
Location: Austin, TX
This can also be done in a single query in PostgreSQL.

MySQL is a toy database. If you can, switch to a real database server

_________________
Read my book, Real OOP with REALbasic
Guyren G Howe
Relevant Logic LLC

guyren-at-relevantlogic.com ~ http://relevantlogic.com

REALbasic, PHP, Ruby/Rails, Python programming
PostgreSQL, MySQL database design and consulting
Technical writing and training


Top
 Profile  
Reply with quote  
 Post subject: Re: MySQL and Linked Lists
PostPosted: Tue Nov 27, 2012 9:13 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
gisborne wrote:
This can also be done in a single query in PostgreSQL.

MySQL is a toy database. If you can, switch to a real database server


Instead of casting dispursions on one database engine vs another... please post the "single query"
as I would be very much interested to see how you manage a recursive function in ONE query.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: MySQL and Linked Lists
PostPosted: Tue Nov 27, 2012 10:38 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
PotsgreSQL has syntax called CTE (common table expressions) that let you do this

See WITH RECURSIVE
http://www.postgresql.org/docs/9.2/stat ... -with.html

there's an example of traversing a parts hierarchy on the page there

(personally I've not used them but I know of other db's that have adopted such syntax to be able to do exactly this kind of query as it is very common)

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group