Paul Lefebvre's Database Tutorial

True, but the functionality is still available. the code

switch(grade) {
      case 'A' :
         printf("Excellent!\n" );
      case 'B' :
      case 'C' :
         printf("Well done\n" );

is functionally the same as

Select Case Grade
Case "A"
  Print ("Excellent")
Case "B","C"
  Print ("Well Done")
End Select

Personally, I prefer the Select Case style. I recall many hours of debugging old C code where I forgot a Break statement in a Case clause.

1 Like

No. In C you have to put a break at the end of each clause explicitly, otherwise execution will fall through and execute the following clause whether or not that clause would have evaluated to true. This is not the case in Xojo, where there is (effectively) an implicit break at the end of each clause, meaning that execution cannot fall through to the following clause. In C, if you leave out all the breaks, then the first matching clause and all those that follow, will be executed.

Perhaps I should have said that, if in C each clause if protected by a break, then at most one clause is executed. The breaks in Xojo are not needed as they are implied. On the other hand, each clause’s condition is tested, until the first matching one is reached, whose clause is then executed (and in C, perhaps more if breaks are missing), but no further conditions (in C or Xojo) are evaluated.

So in Xojo, no more than one clause is executed, ever, matching C IFF there are breaks in all clauses.

Thanks for the question Tim. I declare “MyDatabase” and connect to it via a method called “OpenDatabase”

MyDBFile = SpecialFolder.ApplicationData.Child("Ch12")  
If MyDBFile.Exists Then  
  MyDatabase = New SQLiteDatabase  
  MyDatabase.DatabaseFile = MyDBFile  
    Return True  
  Catch error As DatabaseException  
    MessageBox("Error Connecting to Database.")
  End Try  
  Return CreateDatabase
End If
1 Like

@Bob_Gordon Thanks for the tip, Bob! I’ll definitely try implementing that. And yeah, I’m liking Valentina a lot so far.

@Emile_Schwarz Could you possibly elaborate a little bit? What am I renaming “sql_cmd” and what would be a “TextArea”? Sorry if I’m being sophomoric here.

TextArea is in the LR.

sql_cmd rename: use meaningful names. SQL along may be confusing; you start using this kind of name and faster, you will fall into using reserved names.
And, sql_cmd (SQLite Command “Line”): you (and everyone) understand what it is at the first look.

IMHO. Of course, until you start having troubles with your variables names, you are totally free to use the names you want.