SmartSQL for REALbasic

Overview

SmartSQL is a class created by FreeVBCode.com. We’ve found this class extremely useful in Visual Basic so we decided to port it to Real Studio.

The SmartSQL class is designed to simplify the generation of SQL statements. In projects that require the use of complex SQL statements, developers sometimes have to use (often convoluted) if-then or select logic to concatenate and generate the statement. The SmartSQL class eases this process by allowing the developer to use properties and functions to set up the statement, instead of keeping track of a long string.

The class offers flexibility in terms of how to generate the statement. For example, the field list of a select statement can be specified by repeatedly calling the AddField method or by passing a list of field names as a paramarray or array to the AddFields method.

The class offers the ability to easily re-use aspects of a previously generated statement. For instance, the class allows a developer to easily modify the where clause of a previously generated SQL statement, while maintaining the table list, field list, join clause and/or order clause.

Simple Example


dim oSQL as new cSmartSQL
oSQL.SetupJoin("Customers", "ID", "Orders", "CustomerID", eClauseOp.Equal, eJoinType.Left)
oSQL.AddFields("Customers.Name", "Customers.Phone", "Orders.ID", "Orders.ShippingAddress")
oSQL.AddSimpleWhereClause("Total", 1000, "Orders", eClauseOp.GreaterThan)
oSQL.AddSimpleWhereClause("Customers.State", "CA")

// This MsgBox will display:
// SELECT Customers.Name,Customers.Phone,Orders.ID,Orders.ShippingAddress
// FROM (Customers LEFT JOIN Orders ON Customers.ID = Orders.CustomerID)
// WHERE (Orders.Total > 1000) AND (Customers.State = 'CA');
MsgBox(oSQL.SQL)

Another Example


dim oSQL as new cSmartSQL
oSQL.SetupJoin("Customers", "ID", "Orders", "CustomerID")
oSQL.AddSimpleWhereClause("Age", 35, "Customers", eClauseOp.LessThan)
oSQL.AddSimpleWhereClause("Total", 5000, "Orders", clauseop.GreaterThan, eWhereClauseLogic.Logic_Or)

// This MsgBox will display:
// SELECT * FROM (Customers INNER JOIN Orders ON Customers.ID = Orders.CustomerID)
// WHERE (Customers.Age 5000);
MsgBox(oSQL.SQL)

Using SmartSQL with Xojo

Download the package and unzip. Import the cSmartSQL.rbo, mSmartSQL.rbo and cInvalidValueException.rbo files on to your Real Studio project.

The terms of use from FreeVBCode.com require us to include the original documentation and VB class and dll.

The Real Studio code is provided “As-Is.” You can freely use and modify the code as you see fit provided you adhere to the original terms set forth in the FreeVBCode documentation. If you find any bugs or ways to enhance the functionality in Real Studio, please email us any changes you make.

Download the SmartSQL Project

SmartSQL for Xojo API 2
SmartSQL for Xojo API 2
Xojo-SmartSQL-API-2.zip
12.0 KiB
153 Downloads
Details...
SmartSQL for RealStudio
SmartSQL for RealStudio
RBSmartSQL.zip
305.2 KiB
1058 Downloads
Details...

Leave a Reply