mySQL - read but not write

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dzervas
Posts: 9
Joined: Sun Oct 07, 2007 11:23 am

mySQL - read but not write

Post by dzervas » Mon Dec 24, 2007 4:06 pm

Hi all,

I can successfuly read a mySQL web database using the Query Builder and some fields that only have the inspector DB actions.

I have not written a single line of code for this (yet...).

However, I cannot see how I will create a new record for this database...
If I clear the fields and write something, pressing the "Update" button will not actually read to my database.

Any ideas please?

Thanks

Dennis

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

Post by Janschenkel » Mon Dec 24, 2007 5:59 pm

Hi Dennis,

In order to create a new record in the database, you'll have to write your own SQL query with an INSERT command, and execute it manually. Using the undocumented revExecuteWithQuery command, you can make sure it is sent to the same database as your original SELECT query.

Code: Select all

on mouseUp
  -- assuming you have a query named "AllCustomersQuery"
  put "AllCustomersQuery" into tQueryName
  -- determine the id and name of the new customer here
  put 100 into tCustomerID
  put "ACME Parts LLC" into tCustomerName
  -- assemble the INSERT query
  put merge("INSERT INTO Customers (Id, Name) VALUES ([[tCustomerID]],'[[tCustomerName]]')") into tInsertQuery
  -- now execute the query on the same connection
  revExecuteWithQuery tQueryName, tInsertQuery
  -- after that, you can refresh one or more queries
end mouseUp
The reason why Revolution can't create a new record for you, is that it doesn't have the information needed to do this in a full-proof way:
- is the primary key auto-generated by the database or should it keep track of its own sequence numbers?
- which foreign keys need to be auto-filled with what data?
Not all databases offer enough meta information, and even when they provide it, its value is dependent on the person who added the database schema information.

Hope this helped,

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

Post Reply