put revOpenDatabase("mysql",ServerIPAddress,yourDBName,yourLogin,yourPWD) into dbID
--dbID will contains the ID connexion, always integer
--here i use "mysql", but you can use "sqlite", "odbc" or "postgresql"
if dbID is not a number then
answer warning "Problem :"&dbID
exit to top
put "select col1,col2,col3 from mytable" into dbSQL
put revDataFromQuery(,,dbID,dbSQL) into theData
--by default, columns will be separated by TAB, and record by CR (the first 2 commas in revDataFromQuery)
--but you could use other separators : put revDataFromQuery("|","*",dbID,dbSQL) into theData
if theData begins with "revdberr" then
answer warning "Problem :"&theData
exit to top
--close the connexion to the DB server
put false into pFirstLineContainsHeaders
set the dgText [ pFirstLineContainsHeaders ] of group "myDatagrid" to theData
Quentin Brown wrote:I really feel that Livecode would benefit from a more structure approach to learning with theory and basic principles being explored first, progression from there in logical steps to discussing specific applications and those being explained with multiple examples and possible ways of solving the problems and other possible & related problems and solutions being discussed with a discussion and explanation of best practices along the way.
elanorb wrote: we will start adding links to additional resources to the document that accompanies the video each week.
Quentin Brown wrote:Thanks Bangkok,
As I am coming from filemaker development this is frustrating to me - my app which I am porting to Livecode has been developed with this basic functionality sitting in the background and just a few sections of code to join the dots and add the unique functionality I require and now I find I have to code that basic functionality from the ground up and climb a massively steep learning curve to do so before I can even begin a the point I began at in Filemaker. No doubt many people are in a similar situation and moving from Filemaker to Livecode due to the combination of much greater flexibility and less restrictive licensing model in terms of costs and seats.
Quentin Brown wrote: No doubt many people are in a similar situation and moving from Filemaker to Livecode due to the combination of much greater flexibility and less restrictive licensing model in terms of costs and seats.
I went through a similar experience about 9 months ago, trying the reduce the "get data from a database into a datagrid" problem to its simplest and easiest form.
I found that the best way (for me anyway) was to try to hide/ignore all the revDBxxx calls. I started with Andre Garzia's DBLib package (available at http://andregarzia.com/pages/en/dblib/). I then wrote some scripts that used DBLib to automatically generate a card containing either a form (a page full of label:text-field pairs, one for each column in a chosen database table) or a datagrid (one DG column for each database column). It does this automatically, by reading the DBMS's system tables, which define the contents of each user-defined table. The scripts populate the resulting card, including Next and Prev record, plus Delete and Insert functions.
I gave a presentation on this at RunRevLive 13, and would be happy to send you a copy of the presentation if you're interested...
Even if you don't have an interest in the auto-generated-forms stuff, I still strongly recommend DBLib: a single functions call to DBLib will auto-fill fields or datagrids directly from the results returned from a query, no need to reference each item by name. And DBLib queries are MUCH, MUCH easier to code than the traditional approach described in Lesson 3. No fooling around with breaking SQL WHERE clauses into little quote-wrapped-chunklets-mixed-with-LC-variables!
I'm a huge fan of abstracting all the annoying details away, and of not making app developers struggle with SQL syntax. Andre has done a magnificent job of doing just that...
Users browsing this forum: No registered users and 1 guest