Archive for the ‘Microsoft SQL Server’ 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 Native Client with v10 Flex2SQL MS SQL Server

Tuesday, April 21st, 2009

The v10 SQL Server drivers exclusively use the SQL Server native client libraries.  This is the approach MS is taking and is evident by the fact that almost all new features in SQL 2008 can only be accessed through the native client.

However, as with all things Microsoft, things are not always that simple! In our testing, we have seen anamolies that shouldn’t be there but are. For example, in previous version, we could be sure that older versions of the OLEDB providers would work with newer versions of SQL Server. Simple right?  Not so with the native clients.

When  it is necessary to match up the various versions of  native client versions with the versions of SQL Server. Here is what we recommend:

If you are connecting to  SQL Server 2005,  you can use Native Client 2005 or Native Client 2008 installed.
If you are connecting to  SQL Server 2008,  you MUST use Native Client 2008.  You cannot use the Native Client 2005.

So what does this mean? If your customer has upgraded to SQL Server 2008 without informing you and now are experiencing “weird” behavior  with your application, tell them to make sure they install the Native Client for SQL Server 2008.  And yes, Microsoft wants you to intsall the native client because it is too much for them to just provide a single client connection library like MySQL or PostgreSQL!

The Flex2SQL v10 installation comes with a native client installation, for your convenience.

How and When To Use MS SQL Server Native Client

Monday, February 16th, 2009

SQL Native Client can be used rather than Microsoft Data Access Components (MDAC) to create new applications or enhance existing applications that need to take advantage of new SQL Server 2005 features such as Multiple Active Result Sets (MARS), Query Notifications, User-Defined Types (UDT), and XML data type support.

(more…)

New Flex2SQL for MS SQL Server v10.x Driver Feature: LOB Support

Monday, February 16th, 2009

BLOBs are very large variable binary or character data, typically documents (.txt, .doc) and pictures (.jpeg, .gif, .bmp), which can be stored in a database. In SQL Server, BLOBs can be text, ntext, or image data type.

(more…)

Controlling Locking Behavior With the SET_ISOLATION_LEVEL Command

Monday, February 16th, 2009

SET_ISOLATION_LEVEL controls the locking and row versioning behavior of SQL statements issued by a connection.

(more…)