Quantcast
Channel: FiveTech Software tech support forums
Viewing all articles
Browse latest Browse all 26212

FWHMARIADB Samples

$
0
0
mariainv.prg is revised. [code=fw:16xeeo07][/code:16xeeo07] Please download again the zip file from the link and unzip to any folder and run the exe. Download Link: When you execute, you have a choice to connect to the same demo server in the cloud or your own server. If you choose you can enter your credentials and connect to your own server. The program will create all the tables on your server and proceeed. The revision is made to demonstrate the following additionally: 1) Server capabilities: (a) Calculated columns: MySql server 5.7.1 and the current stable version of MariaDB server both provide this feature. If you server supports this feature, the invoices table will be created using this feature. Please see function CreateInvoices() to notice the difference in the table definition and also the triggers. (b) Check Constraint: As of now only MariaDB server version 10.2.1 supports this feature. We have implemented field validatiosn through triggers. If your server supports this feature, the program creates tables to use this feature. In this case the triggers are omitted in most cases. You can see the syntax how to use CHECK constraint and also how it works during execution, if you install this version of the server. Check constraints can be for a column or for a table. In this sample, we demonstrated only column level constraints but not table level constraints. Table level constraints can compare values of two or more columns like CHECK( thisdate > thatdate ). The constraint can not use indeterminstic values for comparison. For example ( price > 0 ) is accepted but not ( `date` <= CURDATE() ). These kind of validations are still required to be done in triggers only. Please note that using both features of calculated columns and check constrains most of the triggers are eliminated. 2) Edit: While we used FWH default dialog for editing clients, we used programmer's own dialog for Items. This is to demonstrate how to make the dialog and how to define action for the "Save" button. In both the cases, we do not have any validations at the dialog level but totally depend on the server validations. The purpose is the demonstrate how the front-end dialog can benefit from the server-side validations either through triggers or check constraints. However, having the validations in the front-end dialog saves round-trips to the server for validations. 3) ENUM field type: This was included in the first sample also but explained now. Only MySql/MariaDB suppots ENUM field type. At the time of creating the table, we can define the possible values of a column. Only one of the values is accepted as input by the server. Example: [code=fw:16xeeo07][/code:16xeeo07] This works similar to CHECK constrain in other RDBMSs like "UNIT VarChar(5 ) CHECK( unit in ( 'Items', 'K.G', 'Metre', 'Litre' )" but differs in the way of storage. Support to ENUM columns by FWHMARIALIB: When the rowset is created, the permitted choices of the ENUM column also are read. These choices are availble in oRs:Fields( "unit" ):List. When XBrowse is created, the fields is created with EDIT_LISTBOX with these choices automatically, without any effort by the programmer. Sameway the default dialog of DataRow also uses these choices automatically as combobox. Function EditItems() demonstrates how the programmer can use this list to build combobox in his dialog. 4) Updating the values in invoices table from the aggregates in the invitems table: In the case of our sample, the `amount` column is updated when invitems table is modified through triggers. This should normally guarantee the data integrity. But a bad front-end or program can fail this, by directly writing data to this field. However in similar cases, we may like to occassionally refresh the values in the parent table from the aggregates of the child table. Please see function UpdateTotals(). This is done by calling this method: [code=fw:16xeeo07][/code:16xeeo07] This method internally generates the following SQL and executes: [code=fw:16xeeo07][/code:16xeeo07] This demonstrates the use of this method that can be used in similar circumstances, without writing complex SQL statements. Full Syntax: [code=fw:16xeeo07][/code:16xeeo07] 5) Parent Child tables (in the original sample also): When foreign key relationships are defined, creating master child tables is as easy as [code=fw:16xeeo07][/code:16xeeo07] The child rowset can be referred to as oRsInvoices:oChild. The Rowset object uses the foreignkey relationships to relate the `invitems` table to the parent table.

Viewing all articles
Browse latest Browse all 26212

Trending Articles