How to define a field

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
inselfan
Posts: 42
Joined: Fri Nov 10, 2006 11:33 am
Location: Menorca, Spain

How to define a field

Post by inselfan » Tue Nov 21, 2006 10:52 am

Holá everybody,

I do not find out, how to get a field from a MySQL Database. With:

put "SELECT * from table where Masc_name=" & q (tPath) into SQLBefehl
put revdb_query (DB_ID,SQLBefehl)into temp1

With this, I can select the right Table and the right record, but how to put one of the fields of this record into a local defined Variable??? Please, if you have an answer, let me know.

best regards and thank you

Inselfan

oliverk
Site Admin
Site Admin
Posts: 53
Joined: Mon Feb 27, 2006 2:16 pm
Location: Edinburgh

Post by oliverk » Tue Nov 21, 2006 4:14 pm

Hi Inselfan,

You can do this using the revdb_querylist function.

Try something like this:

Code: Select all

put revdb_querylist(tab, return, DB_ID, SQLBefehl) into tQueryResult
This should put the result of the select query into the variable tQueryResult, with each column separated by tab and each line separated by return.

Hope this helps

Regards
Oliver
Oliver Kenyon
Software Developer
Runtime Revolution

inselfan
Posts: 42
Joined: Fri Nov 10, 2006 11:33 am
Location: Menorca, Spain

Post by inselfan » Wed Nov 22, 2006 10:09 am

Hola Oliverk,

Thanks for your Reply, That's what I also found out, but I need just 2 fields and my question is, how to put this 2 fields into Variables. Is there an other way?

best regards
Inselfan

oliverk
Site Admin
Site Admin
Posts: 53
Joined: Mon Feb 27, 2006 2:16 pm
Location: Edinburgh

Post by oliverk » Wed Nov 22, 2006 11:49 am

Hi Inselfan,

I think the best way to do this is to use the SQL query to return
only the fields that you are interested in, otherwise your program
will be doing more work than it needs to. I think the syntax is something
like "SELECT field1, field2 FROM table WHERE ..."

Alternatively, you can set the itemDelimiter to tab in Revolution and write
a function that extracts the fields you want.

Regards

Oliver
Oliver Kenyon
Software Developer
Runtime Revolution

inselfan
Posts: 42
Joined: Fri Nov 10, 2006 11:33 am
Location: Menorca, Spain

Post by inselfan » Wed Nov 22, 2006 1:57 pm

Hi Oliver,

Thanks and you tell me something I also figured out :-)

But THERE is my handicap. If I write:
put "select........." into Variable then (and I think now you smile) I find exact select......... in my variable. Which looks nice but doesn't make me happy

so, PLEASE, what is the right word instead of PUT?

a beginning user called
Inselfan

andrew@ugh.net.au
Posts: 13
Joined: Sun Dec 17, 2006 12:30 pm

Post by andrew@ugh.net.au » Thu Jan 04, 2007 8:23 pm

I think what your asking for is something like this:

Code: Select all

put revQueryDatabase(dbid, sql) into results_set
if results_set is not an integer then
  -- query failed
  if the number of items in results_set is 2 then
    -- results is probably revdberr,blah
    put item 2 of results_set into results_set
  end if
  warning "Query failed:" && line 1 of results_set
  exit mouseUp
end if
   
if revNumberOfRecords(results_set) = 0 then
  warning "No records found"
  exit mouseUp
end if

answer "Field foo =" && revDatabaseColumnNamed(results_set, "foo")
answer "Field bar =" && revDatabaseColumnNamed(results_set, "bar")
Hope I have understood the question and this helps somewhat.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”