Page 1 of 1
mySQL - read but not write
Posted: Mon Dec 24, 2007 4:06 pm
by dzervas
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
Posted: Mon Dec 24, 2007 5:59 pm
by Janschenkel
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.