
![]()
Copyright © 2007 SoftVelocity, All rights reserved worldwide |
|
Clarion Language Clarion's Application Generator is so powerful that many Clarion developers write amazingly little "hand code." But because the code that the Application Generator generates is in fact Clarion language code, anyone who really wants to know about or learn how Clarion works should examine the code and learn the programming language. Clarion allows for a rich variety of data types, including reference variables, which are similar to pointers but "safer." It provides an object oriented structure, including support for classes, as well as inheritance, encapsulation, and polymorphism. A simple "Hello World" program can be found here. The rest of this section will concentrate on how the language handles database access. Clarion, unlike some other development environments, was designed for database access. Clarion is a data aware language, as opposed to a general purpose language with data access libraries. The core data elements are FILE and RECORD. These are descended directly from COBOL. The FILE is a data type that describes a table. The RECORD is a data type that describes the columns in the table. The following is a FILE declaration: Detail FILE,DRIVER('Scalable'),OWNER('pervas|EXAMPLE'),NAME('Detail'),PRE(DTL),BINDABLE,THREAD The FILE declaration describes a table called "Detail" on a Pervasive.SQL 2000 database server called "pervas," in a database named "Example." It describes access via one of Clarion's pluggable file drivers (called "Scalable," because we didn't update the name of the driver when the database product name was changed!). It further describes the keys and indices, including the internal names used by the database. The RECORD is nested inside the FILE declaration. It describes the column names and datatypes. Note the prefix ("DTL"). In referencing any column, Clarion code prepends the prefix to the field name, as in DTL:CustNumber. To establish a connection, the developer can simply use the OPEN statement, with the name of the FILE: OPEN(Detail) To choose a particular key or sort order, the developer can use the SET statement: SET(DTL:KeyDetails) To fill the record buffer with the first record, the developer can use the NEXT statement: Next(Detail) Or, to position the record pointer at the record for customer 1234 (the "Details" key is customer number key and contains no duplicates because it's the primary key), the developer can put the value they want to find in the record buffer, and then use the GET statement: Detail.CustNumber = 1234 With the desired record now in the buffer, if there is a control in the current window pointing to the customer number field, it will now contain the customer number for this row (this is accomplished through the USE attribute on the control, which would point to the data variable with it prefix and field name, which is DTL:CustNumber). If the end user changes the information in the control, after the ACCEPT loop (which gets the end user input), the developer can update the record (assuming that it's still the current one in the buffer) with: PUT(Detail) If the developer then wishes to close the connection to the database: CLOSE(Detail) This is a simple overview. In practice, there would be much error handling: what if the network were down and we didn't connect? What if the record for 1234 were not found? What if someone else had locked the record? The templates generate all required error handling. SQL AcceleratorsOne aspect of the Clarion database support is that all Clarion language commands for database access work with both ISAM files such as Dbase, and with SQL backends like Oracle, MS-SQL, etc. This is accomplished either with the supplied ODBC interface or with our SQL database drivers. SoftVelocity's SQL Accelerators support all of the common Clarion driver features. The SQL Accelerators convert the standard Clarion file I/O statements and function calls into optimized SQL statements, which they send to their backend SQL servers for processing. This means you can use the same Clarion code to access both SQL tables and other file systems such as Dbase or Clarion files. It also means you can use Clarion template generated code with your SQL databases.In addition to the SQL statements the driver creates as SQL Prepared Statements when it is communicating with an SQL backend, the SQL Accelerators also allow you to embed and send any SQL statements you specify to the SQL server. The SQL Accelerator retrieves the result set returned from the SQL server and makes it available to your application program with the Clarion NEXT or PREVIOUS statement. This capability lets your program do backend operations independent of the SQL Accelerator driver's generated SQL. For example, multi-record updates can often be using a Stored Procedure on the SQL backend. In cases like these it makes sense for you to take control and send custom SQL statements to the backend, and PROP:SQL lets you do this.
|
||||
Copyright © 2007 SoftVelocity, All rights reserved worldwide |