Archive for the ‘MySQL’ Category

Multiple embedded SQL statements

Tuesday, June 30th, 2009

While complex embedded SQL statements will let you do a lot of work in one statement, it is sometimes necessary to nest SQL statements to get the job done.

Using cursor handling lets you easily nest multiple embedded SQL statements.

Consider the scenario where we want to iterate through all orders with a specific status, and for each order we want to calculate the total of that order.

Of course, in this case it would be pretty easy to write one SQL statement that returns everything, but for the example we will use two nesting calls:


// Example
Use Mertech.inc
Integer iCursor1 iCursor2
Integer iCustomer
String sName
Number nOrder nTotal

login 'Server' 'User' 'Passwd' 'Driver'

set_database_name to 'DataBase'
sql_use_database 'DataBase'

Sql_Open_Cursor_Stmt to iCursor1
Sql_Set_Stmt to "select customer_number,name from customer order where status = 'Y' by customer_number"
Sql_Prepare_Stmt
Sql_Execute_Stmt

Repeat
// Back to the main cursor
Sql_Set_Current_Cursor_Stmt to iCursor1
Sql_Fetch_Next_Row into iCustomer sName
If (Found) Begin
// Open a new cursor to the new stmt
Sql_Open_Cursor_Stmt to iCursor2

Sql_Set_Stmt To ("Select sum(order_total) from Orderhea where customer_number = " + trim(iCustomer))
Sql_Prepare_Stmt
Sql_Execute_Stmt
Sql_Fetch_Next_Row into nOrder
If (Not(Found)) Move 0 to nTotal

Sql_Close_Cursor_Stmt iCursor2

// nTotal has the Order total for this current customer
// Your code here
Indicate Found True
End
Until (Not(Found))
// End Example

The keys in the example are the calls to Sql_Open_Cursor_Stmt and Sql_Set_Current_Cursor_Stmt which allows you to switch between two open recordsets.

Using Auto-Reconnect in a Cluster Situation

Tuesday, February 24th, 2009

For customers who have a full blown cluster just as in database mirroring, typically when testing a failover, there is a hiccup of a few seconds. Our auto-reconnect feature has been able to detect the failover and continue working without problems.

(more…)

New Command: SQL_ENABLE_RECONNECT

Monday, February 16th, 2009

SQL_ENABLE_RECONNECT allows the MySQL Driver to automatically reconnect to the server after the connection has been closed by a time-out. In the MySQL my.ini file you can set a system variable called wait_timeout to set the number of seconds that the server will wait on a non-interactive connection before it closes the connection. The default value for this variable is 28800 (8 hours). See also the MySQL manual under Server System Variables and more specifically the variables wait_timeout and interactive_timeout. (more…)

Some Flex2SQL Assumptions

Monday, February 25th, 2008

This is common list of assumptions we have for all drivers:

(more…)

MySQL License Terms

Monday, February 25th, 2008

MySQL has two different types of licensing agreements.

Open Source license (GNU) and the other more applicable to developers is their Commercial license. Below are excerpts from the MySQL documentation.

NOTE: Since Mertech’s drivers are not open source; anyone using our drivers along with MySQL must purchase a Commercial license.

GNU

The MySQL software is released under the GNU General Public License (GPL), which probably is the best-known Open Source license. The formal terms of the GPL license can be found at http://www.gnu.org/licenses/. See also http://www.gnu.org/licenses/gpl-faq.html and http://www.gnu.org/philosophy/enforcing-gpl.html. Since the MySQL software is released under the GPL, it may often be used for free, but for certain uses you may want or need to buy commercial licenses from MySQL AB at https://order.mysql.com/. Older versions of MySQL (3.22 and earlier) are subject to a stricter license. See the documentation of the specific version for information.

Please note that the use of the MySQL software under commercial license, GPL, or the old MySQL license does not automatically give you the right to use MySQL AB trademarks. See MySQL documentation section 1.4.4 MySQL AB Logos and Trademarks.

Commercial

You need a commercial license:

  • When you link a program with any GPL code from the MySQL software and don’t want the resulting code to be GPL, maybe because you want to build a commercial product or keep the added non-GPL code closed source for other reasons. When purchasing commercial licenses, you are not using the MySQL software under GPL even though it’s the same code.
  • When you distribute a non-GPL application that only works with the MySQL software and ship it with the MySQL software. This type of solution is actually considered to be linking even if it’s done over a network.
  • When you distribute copies of the MySQL software without providing the source code as required under the GPL license.
  • When you want to support the further development of the MySQL database even if you don’t formally need a commercial license…