Thereis a freeware version( ), but to use all possibilities, like serial...one must buy it, but it is rather cheap:
It is a very simple language, successor of GWbasic or Quickbasic, for old people like me...
Have you tried any of the more modern languages like Java or C#? I honestly don't think they're any more difficult than Basic, and you can get fully fledged development environments for free to try them out. I cut my teeth on ZX81 basic...
If you cut your teeth on Quickbasic then Liberty Basic is just fine. It's a well done version basic that fills a gap between "the good old days" and using a full fledged version Microsoft Visual basic.
As you can see from his sample, Liberty basic is very much up to the task. It is a true RAD coding tool since it is not bulky or overweight with optional heady concepts like OOP and such. If you just want to perform SERIAL I/O and make a quick and easy user interface you really need a modern language like JAVA?
Simple to use is not a bad thing. I used to think JAVA was OK but now with each release since I started using it... I think more that it's just a huge behemoth that is crushing itself under it's own weight. The JRE kernel in java 6 is twice the size of java 5... yikes.
We are talking audio CDs here. Lots of Audio CDs. At the last count, my partner and I had 1500 albums between us, which must be at least 20000 selections to keep track of. How sad is that? On the other hand, the wish to know how many different versions of "In the Pines" or "City of New Orleans" we had meant we had to think about putting things "in the computer". I had to think about using a database, or writing one!
Enter Liberty Basic, with it's wonderfully direct approach to GUI programming, and the ability to see all the code in one window if you need to. It seemed ideal for the job of input and display, but then what about the database itself? This led me to explore several approaches to database programming in LB, and in turn to contribute this article. We will come back to those piles of CDs later.
This article is for beginners, so do not expect advanced database manipulation. I do not know how to do that. I cannot as yet even index my finger, let alone my fields. But in a sense we are all beginners at using database managers in LB, because the tools to do this are newly developed. What I hope to do in this article is to explain the use of a database manager in LB, using very simple tasks - defining a database structure, opening it, adding records, modifying records, deleting records, performing a simple search, and finally closing the database. I will do this by reference to an application programme based on - you guessed it, Music CDs - specifically details of singers.
The database manager I have chosen is SQLite, because I have become most familiar with this. It is not the only method that can be used to add database functionality to LB. Much can be done with LBs native file handling commands, especially in Random mode. Also Dennis McKinney has recently produced an example of accessing Microsoft Database structures from within LB (see LB News #102). The Cheetah database manager from Paul Sqires, with an LB inferface written by Walter Decker is also well worth looking at. I intend also to illustrate database use with the Tsunami database manager in a future article.
The example programme is kept as simple as possible. For this reason it runs in the mainwindow, rather than through a GUI, although it is relatively easy to link to a GUI with buttons, menus, list-boxes and the like. This would also allow the easier referencing of one set of data from another.
If dbase$ includes a path, then a file in any directory can be used, or even a file name obtained from a file picker dialog. But note, however, that consolesqlite.bas contains very little error checking, and if you try to use a non SQLITE file, the programme will not tell you, but will just fail. After the dbase$, the dll call passes a value '0 as long'. This value is required, but is not used by SQLite. Any integer can be used.
Note that "sqlite_open" is a dual purpose call. It opens a database if it finds it, but it will create a new one if none exists in the location specified by dbase$. Be careful therefore, about knowing where your existing databases are stored, as you can easily create multiple instances of database files with the same name, but containing different data.
The appendix to this article explains some of the workings of GetTable() and the functions it calls in turn. I have gone into this in some detail, mainly because I think it is clever and I am proud of it! At 54 I have to get pleasure out of something! However, most users will not need to concern themselves with these details. To use GetTable() in your own programmes you must include the following in your main programme, preferably near the top.
When called, GetTable() either changes the contents of the database, adding, deleting or modifying the records, or it reads back information about the records into a two dimentional Liberty Basic array called fields$(). We will see examples of both of these modes of action in what follows.
Creating a database structure is relatively easy in SQLite. All that is required is to name a 'table', define fields for that table, and tell SQLite what you want. SQLite allows many tables to be created within a database, thus easily enabling the creation of links between different sets of data (relational database operations), but for this example I have created only one table. Here is the code :
Strictly speaking, these lines are unnecessary in this application, as the database already exists, and therefore does not need to be defined. However, if the file did not already exist (in the selected directory) these lines would define it, so that records could be added.
There are a couple of things to note about these lines of code. Firstly, we ignore the value returned by GetTable(). This value is actually an error code from SQLite, and it might be useful to print it out to the MainWindow during debugging. In the final application however, we will generally ignore it.
The second thing to note is the length of query$, spanning two lines of code. The power of the SQL database language lies in the flexibility of the various query strings that can be used. Although they are simple text strings, and seem to be in natural language, in fact they are highly structured, with a precise syntax of their own. Because of this, it is often useful to check their effects directly on a database, before using them within a programme. Richard Peeters has produced an application to do just that (see lbNews #105), and SQLite provide their own monitor that runs in a dos window.
So what does this phrase "create table singers (... ) " mean? This is not the place for a full discussion of SQL commands, but the above means roughly "create in the present database file a table called singers." A table is a 'framework' to contain a collection of records (called in SQL rows) with each record made up of a number of fields, or individual items of data( called by SQL columns). In this table, each record has a field called 'firstname', that can be up to 20 characters long, a field called 'lastname', also of characters that can be up to 20 characters long, and the same for 'genre' and 'identity'. All the fields in this table happen to be character fields. Other field types could be used, including numbers or dates.
The first thing we do is to create a query$ to send to GetTable(). "select * from singers" will return everything in our table, which is a good place to start. This loads our data into the array fields$(row, column). The number of rows we have in the table is given to us by the contents of nr.numrow.struct, which we copy into the variable 'count' for ease of understanding.
We may in fact have no data, if the database is empty. We need to check for this and print an appropriate message. If there are records, we use an inner and an outer loop to print out columns and rows of data, using count and nc.numcol.struct as indices of these loops. I have used a Select Case structure here to control programme flow. If, Then, Else, End If would have worked perfectly well.
How do we add a new record to the database? We get the data we need for each field and then compose a query$, using the key phrase "insert into singers values( ", followed by the values of the fields we wish to use for this new record. Simple really. Lets see that in the programme.
gosub[GetRecord] gets user input for the various fields of the record, ie firstname, lastname etc, as f$, l$, g$, and id$. But look at the query$. This consists of multiple parts. Some are Literals in double quotes " etc ". whilst some are the string variables we have just collected. The layout of the finished string is critical. For example, each variable (f$, l$, g$, id$) must be immediately preceded by a ', and immediately followed by a '. If there are extra spaces here, the query will fail. Similarly if brackets or commas are wrongly placed, the query fails. For this reason during testing I often print the query$ as a notice, so that I can check it's construction and identify any error.
First we check that a valid record number has been selected (with a GUI based application this is not even a problem) then make the query$. the keyword 'delete' is self-exaplanatory. However, we only want to delete one record. The 'where' keyword in SQL is used to limit the application of a command, only applying it to our selection. The problem we have here is that the database, as we have defined it, does not allow us to refer to a specific record by its record number. This is where the 'identity' field comes in. We need to retrieve the contents of the identity field for the record we want, which we do with 'fields$(r,4)' (r for the record we want, 4 for the fourth field defined, ie identity). We then insert this into our query$, and ask SQLite to delete away.
No surprises here. This simply combines all the techniques we have used in adding and removing records. However, Look at the construction of query$. Four string variables and a string array member must be embedded in the final string, together with commas, single quotes, double quotes and = and + signs. All must be precisely placed.
3a8082e126