denis.belisle
asked this on January 11, 2010 22:24
Hi,
I have been trying to use SQLYoga with a local Valentina database, without success. I could post the code I used here and explain variants I have tried, but I feel this would not be very productive. What would be very helpful however is a real concrete and complete example of how to connect to the database, retrieve all the data from a given field in a given table and put it in a text field on a card, say by going with the array method. Let's say the db is named "test.vdb in a folder named "test" in the same folder as the Revolution executable, it has one table named "table1", and two fields, named "field1" and "field2". "Field1" contains three records with respective values: 1,2,3. "Field2" contains the respective values: 4,5,6. So... a stack, with one card, having one text field and one button which when clicked will make "1 2 3" appear in the text field. All scripts on the card with a simple call from the on mouse up message from the button. No error catching, no baby steps, just the working code - if it works out of the box, I'll figure it out. It seems that here are some idiosyncrasies in SQLYoga that are beyond me at the moment. So, if someone from Blue Mango could provide such an example, it would somehow lessen the slope of the learning curve by providing something solid on which to build further comprehension.
Thanks in advance,
Baz
Comments
Hi Baz,
This information is actually quite useful for me. You mention that you are using a Valentina database but all I know is that you aren't having success. If you have reviewed the lesson that shows example syntax of connecting to a Valentina database then we need to track down at what point things go wrong.
Connecting to a Database Using a Connection Object
Maybe the problem is that you are not getting the proper path to the file on disk? Maybe it is something else. Seeing your code or having a full description of what you have tried helps me track that problem down. It also helps me see where the holes are in the documentation. What assumption did I make that wasn't clear?
Have you been through the tutorials that are already posted? Even if you aren't using SQLite all of the concepts will be the same.
Fastest and simplest: French Regions Example
More Detailed: SQL Yoga To-Do Application
The French Regions tutorial isn't too long and shows you how to get all the data from a table and put it into Data Grids and fields. All of the major handlers are on the card script so it should be easy for you to dissect. If you haven't looked at that particular manual yet then I would recommend it. If you are still have trouble after looking at it then let me know where you are stuck.
No we don't. Maybe you do, to improve your lessons - not my goal. I do however appreciate the time and candor you did put in your reply. But I simply don't have enough OCD in me to do tutorials like that for very long, of which I already know more than half, and the other half I'll pick up so much faster with a "clean" example. You see, learning has really not much to do with steps, it's more a question of rhythm. Like if you have a really big and heavy box that you need to bring up a long and narrow staircase. Climb too fast and you may miss a step, go to slow and your arms will tire and you may drop the box. There is a very specific speed at which this task is to be done safely and completely; and I was merely only naming my speed. Besides, if there is something I learned after teaching at the university for more than 20 years, and being in the multimedia business for as long: be it from a client or a student, if you can give them exactly what they ask for, you do.
For the record, yes I gave a shot at the first tutorial, its how I got stuck at the connecting to the database phase. The "French tutorial" is useless here: not Valentina, the database object is already created (you load it from the button custom property), and afterwards the code is way too cute to really be pedagogical.
Baz
Agreed. The instructions are present for those who need them. The source code is available for those who don't. It appears you just want less source code which I can appreciate.
Interesting. I've found that what people ask for, whether students or clients, isn't always what they need (generally speaking, not saying this is the case here). Understanding what they are really after is important before trying to provide an answer or doing the actual work. My approach with students and clients has always been to understand what the real need is and then attempt to give them that. I apologize if this annoyed you.
Connecting to Valentina (or any other database) is done through a Connection object, not a Database object. The fact that the Database object exists doesn't affect how Valentina would be handled. You only mentioned you were having trouble connecting, not creating the Database object so I assumed you didn't need to know how to create the Database object.
For a local Valentina database the code that sets the Connection object properties is the exact same for Valentina as it is for SQLite. The code in the French Regions example applies to local Valentina databases more so than any other database type because of the following:
A) Locates a database file relative to the stack that is running the code.
B) Sets the 'file' property of the Connection object to that database file.
C) Connects to the database.
After connecting to the database all SQL Yoga code will be the same. While the French tutorial is not in the format you are looking for it is actually very applicable to what you are doing.
I should point out that I was mistaken when I said that all of the code is in the card script. The code for each tab in the tutorial is actually in the group that represents each tab. The To-Do example has all of the code in the card script.
Different developers are looking for different types of examples I suppose. Personally I don't like examples that don't show how to deal with errors in a library (a shipping app has to know how to handle library errors properly) or how to use the code in a real world scenario which is why I create my example stacks the way I do.
For this reason the code shows how to use SQL Yoga to query a database in a variety of ways and then place that data into a couple of different UI controls.
The code also shows how to determine if an error occurred during certain operations. Again, while not in the format you are looking for it is still educational for people who need to know this type of information.
That being said I can see how a barebones example stack that creates the necessary objects could be useful for understanding the basics. I have created a simplified stack using the French Regions database. The stack connects to a SQLite database because it is more standard and thus more applicable to most of my customers. I have included code and a database that shows how to do this with Valentina though.
There is a minimal amount of error handling. If there wasn't the example could not provide any feedback as to whether or not the database connection was properly established.
You can download the primer here:
http://www.bluemangolearning.com/download/revolution/sql_yoga/sql_yoga_primer.zip
If it isn't too much trouble I would appreciate knowing if works for you. If it does then I can add it to the list of generally available resources.
Baz - I think we could have a very interesting discussion on teaching someday if we ever have the opportunity to sit down and chat. Thanks for taking the time to respond as I've learned a lot from our discussion.
Excellent points and I agree. I would just add that often the client/student intertwines what they want with the approach they think they should take to get what they want. In some teaching scenarios it is best to let the person work their way through the problem, finding out why the approach is wrong along the way. In others it is best to point out the flaw in the approach early on so as not to waste money or have a failed/behind schedule project.
With SQL Yoga I'm dealing with developers who are trying to make money with my library. It is important that I get right to the point and get them up and running as quickly as possible.
You are right - breaking up what you are teaching is key. Looking at the manuals I have so far there are three categories:
A) The SQL Yoga how-to manual: Discusses general concepts about the library and discusses the various components. The intention is for this manual to be the introduction to various concepts in the library but it is far from complete at this point. I have a lot of draft chapters sitting on my computer.
B) The French Regions example stack: This shows various features of the library. This was the original stack used in the webinar that introduced the library.
C) The To-Do Application: Full featured application showing how to integrate the library from start to finish in an application that you could ship.
I'm not sure how useful (B) is in it's current state as it was not created with teaching the library in mind, merely demonstrating. (C) is intended for the person trying to create an application with the library and thus needs to know how to properly integrate the library into an application. I have people like that who take the App Development Course which is why (C) was created early on.
(A) was missing the example stack that you were looking for - a raw testing playground that shows the very basics. I'm going to add the stack into the beginning chapter.
I'm my own worst enemy :-) Do keep in mind that not everyone is as experienced as you. I have to be somewhat defensive in the coding and explanations as there are things that can go wrong due to the nature of the Revolution IDE and to help those with less understanding of what is going on get through it all. It's a fine line but I try to cover the issues that I have had to address in previous support emails.
I'm glad you got things working!