Help with DB table 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
bichuf
Posts: 3
Joined: Sun Apr 27, 2008 3:03 am

Help with DB table field

Post by bichuf » Wed May 14, 2008 1:59 pm

Totally new to this.

Have one stack with a table field connected to a SQLite DB. Works fine.

Another stack has the labels and fields to create a new record for the DB.

Put a button on 1st stack to Add a new record.

Want that to pop up the second card to input new record and save it to the DB.

Also, how can I put in column titles on the table field and how can I make the columns resizable?

Thanks

bichuf
Posts: 3
Joined: Sun Apr 27, 2008 3:03 am

Would have thought...

Post by bichuf » Sun May 25, 2008 1:51 am

that this would be answered by now. Wow! This is a piece of cake in something like PHP. Is it so hard in RR? If there is no way to create a table grid with column tittles, well that is really odd. There has to be a way. Does noone work with databases in RR? Any takers? Last chance before I call it quits on RR!

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sun May 25, 2008 7:55 am

Hi there,

Plenty of Rev developers build database front-ends. Some of the questions you are asking, are not straightforward to answer.

The key thing to remember is that Revolution is a tool to build destkop applications, which sports extensions to connect to databases. It is not PHP or ASP.NET - but no single programming language has it all without a learning curve.

Maybe it's best if you follow the Revolution User Guide (which you can open from the documentation), and download Srah Reichelt's examples here: http://www.troz.net/Rev/tutorials.php

Let's start with table column headers: they're not supported by the core product, but you can download the altFldHeader plugin here: http://www.altuit.com/webs/altuit2/altP ... nloads.htm

On to navigation between stacks: the 'go' command is your friend here. So your 'Add a new record' button should have a script like this:

Code: Select all

on mouseUp
  go stack "RecordEditor"
  -- add some code to reset the data in the editor stack
  ...
end mouseUp
An here's how you can react to a doubleclick on a list field, by adding a 'mouseDoubleUp' handler to your field's script:

Code: Select all

on mouseDoubleUp
  put the hilitedLine of me into tLine
  go stack "RecordEditor"  -- the name of your editor stack
  -- now do something to initialize the stack
  ...
end mouseDoubleUp
If you want to make sure the user can't click on other windows in your application while editing a record, use the 'go ... as modal' variant.

Actually creating a record in your database table will involve some SQL. You collect the data that the user entered, run a database query to insert the record, and then refresh your table. So your "Save" button would have a script like:

Code: Select all

on mouseUp
  -- assuming the database connection is stored in this global variable
  global gDatabaseConnection
  -- read the data the user inserted
  put field "FirstName" into tFirstName
  put field "LastName" into tLastName
  put field "EmailAddress" into tEmailAddress
  -- now prepare our query
  put "INSERT INTO Customer" && \
      "(FirstName, LastName, EmailAddress)" && \
      "VALUES (:1,:2,:3)" into tSqlQuery
  -- next execute our query
  revExecuteSQL gDatabaseConnection, tSqlQuery, "tFirstName", "tLastName", "tEmailAddress"
  -- finally close the editor stack
  close this stack
end mouseUp
Hope this gets you started,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sun May 25, 2008 11:15 am

Forgot the link to the Databases Workshop at runrev.com: http://www.runrev.com/developers/explor ... databases/

That should give you a pretty good idea of how to build a database front-end using Revolution.

Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bichuf
Posts: 3
Joined: Sun Apr 27, 2008 3:03 am

Post by bichuf » Tue May 27, 2008 2:23 am

Jan:

I am very grateful to you for taking the time to post such a helpful reply. I have downloaded and used the fldHeader plugin and that did the trick for me. I still find it a bit rudimentary and the instructions on use were not very clear, but it does the job although it did give me a hard time at first. But I finally got a 7 column table with titles and resizable columns! I can edit the data directely in the table now.

Will be looking at the other examples you provided as well as the links. I still have not decided if I'll stick with RR yet. Not much info out there and the sites that do exist are pretty outdated. Last review MacWorld wrote was like for V.2.1 or near that. Am looking at Xcode and QT also.

Again, thanks and best regards.

Guillermo

Post Reply