June Fourth 2009 From: Bob Zale, President PowerBASIC, Inc. PowerBASIC Gazette #68 ====================== Subject: Database Programming with PowerBASIC ============================================= There's important news from the Gazette... I'd like to take a moment of your time to tell you about one of the most important "Add-On" products for PowerBASIC. Perfect Sync SQL Tools. You can have it in your hands this afternoon. It's just that simple. If you need Database Management in your code, you need SQL Tools 2. Stay with me, I'll convince you. In fact, I'll start the story right at the beginning. So Just What is SQL? SQL stands for "Structured Query Language". Some folks pronounce it "Ess-Cue-Ell", and some say "Sequel", but most everyone agrees it's a very powerful database tool. The syntax of the language resembles BASIC, but it may even be closer to plain natural English. Let's suppose your instructions were: "Give me all of the records in my AddressBook database where the value in the State field is "California", the Age of the person is greater than 18, and the PhoneNumber field is not blank. Show me the FirstName, LastName, City, and PhoneNumber fields, and sort the records in ascending order by ZipCode." Imagine writing the code to do that procedurally. It wouldn't be trivial. Do it with SQL in a single statement: SELECT FirstName, LastName, City, PhoneNumber FROM AddressBook WHERE State = 'California' AND Age > 18 AND PhoneNumber <> '', ORDER BY ZipCode Issue that request, then read the data. It's just that simple. No worries about file formats, indexes, linked lists, hash tables, or anything else. Construct a simple string, and the database does your work for you. Of course, SQL is a complete database language. You can insert, delete, or update data, search, sort, and select with equal ease. SQL Databases are Relational Databases. Suppose you need to store product orders. Create a SQL table (like a grid) called Orders, with a CustomerNumber column, a QuantityOrdered Column, and a ProductNumber column. Then create a table called Customers that contains a CustomerNumber column, a CustomerName column, and a CustomerAddress column. Now, create a table called Products, with columns called ProductNumber, ProductName, and Product Price. The beauty of a relational database? Each unique value is stored only once. Even if 10,000 different customers order your special product "Acme Industries Super-Widget 2000", that string will appear in the database once. When the text name is needed, the system finds it automatically. Perhaps even better, when the product name changes to "Acme Industries Super-Widget 2000 Plus", you change it once, and every record in the database reflects it instantly. SQL databases are also Multi-User. Twenty clerks can enter orders at the same time that reports are generated or products redefined. The bottom line is simply this: SQL becomes a database management language of its own, encapsulated within PowerBASIC, or even some other programming language when necessary. A very powerful tool for your applications! How Does SQL Tools Fit in this Picture? SQL Tools offers a straightforward interface to ODBC, the Windows Open Database Connectivity Engine. ODBC is an integral part of 32-bit Windows, and is automatically installed in all but the earliest versions. Even then, it's just a free download from the Microsoft Web Site. SQL Tools, and the simple language shown above, will work with virtually any database compatible with ODBC. And Performance? It's absolutely better or equal to ODBC! SQL Tools works with virtually any DataBase! Microsoft Access, MySQL, SQL Server, Oracle, Btrieve, dBase, Paradox, Excel, FoxPro, and more... In fact, ODBC drivers are available for more than 50 popular databases, and toolkits are available for writing custom drivers. SQL Tools provides compatibility with the ODBC Version 3.5, Level 2 specification, which is the current state of the art for ODBC databases. Complete ODBC 3.5 support means you can read and write .MDB files without using Microsoft Access... You can read and write .DBF files without using FoxPro or dBase... You don't have to use any DBMS software! The bottom line is that SQL Tools provides very fast, very efficient, access to almost any popular database files in the PowerBASIC tradition - WITH NO BLOAT! What Does a SQL Tools Program Look Like? Here's the PowerBASIC source for a simple program that opens a database, retrieves all of the data from a table, and saves it to a text file: FUNCTION PBMain OPEN "\SQL-DUMP.TXT" FOR OUTPUT AS #1 SQL_OpenDatabase "DSN=SYS1; UID=JOHN; PWD=;" SQL_Statement %IMMEDIATE, "SELECT * FROM ADDRESSBOOK" DO SQL_Fetch %NEXT_ROW IF SQL_EndOfData THEN EXIT LOOP PRINT #1,SQL_ResultColumnText(%ALL_COLs) LOOP CLOSE #1 END FUNCTION Database doesn't get much easier, does it? A fully functional SQL Tools program in that very small space! Don't be fooled by the simplicity, though... SQL Tools provides everything you'll need to build powerful, flexible, multi-user programs. What's the Difference Between Standard and Pro? SQL Tools Standard contains all of the functions you'll need to create programs which read and modify SQL databases. The entire text-based, single-statement SQL language is supported. SQL Tools imposes no limitations on the SQL syntax supported by your ODBC drivers. And of course, you can distribute either SQL Tools DLL with no additional cost or royalty expense. SQL Tools Standard allows a program to have one or two databases open at the same time, and each database can use one or two SQL statements at a time. SQL Tools Pro supports up to 256 databases by one program, each having up to 256 concurrent SQL statements. You also get... * Manual Commit/Rollback of Transactions * Stored Procedures (pre-compiled SQL statements) * Batched SQL Statements * Bound Statement Parameters, with Long values and arrays * Relative Fetches * Bookmarks * Support for MultiRow (Block) Cursors * Bulk Operations * Positioned Operations * Named Cursors * Connection Pooling * Multithreaded Operation * Low level SQL/ODBC Diagnostics * Extended Info Functions... What Will I Need To Use SQL Tools? You'll need a 32-bit Windows operating system, like Win98, Win2000, WinXP, or WinVista, a 32-bit compiler (like PowerBASIC for Windows or PowerBASIC Console Compiler), and the ODBC Driver for the database you want to use. Free ODBC drivers for most databases are available. If you want to design a complex relational database (as opposed to working with an existing database) you may wish to consider getting a GUI-based "DBMS" database management software, such as Microsoft Access or Oracle SQL*Plus. Of course, if you distribute a program, you only need to distribute the ODBC driver, never a DBMS package. What's Included With SQL Tools? You'll get SQL Tools with royalty-free distribution rights, the SQL Demo DLL, and the huge SQL Tools Help File. You'll get all the $INCLUDE files you'll need, and even sample programs with a database. SQL Tools Documentation is provided in Windows Help File Format, and it offers a lot. More than 800 pages, filled with function examples, tips and techniques, with many Windows, ODBC and SQL related topics. It's also available in Adobe PDF format to allow easy printing, searching, and annotation. How do I get even more information? Simple... Just GOTO http://www.powerbasic.com/products/sqltools/ So how do I buy SQL Tools today? That's the easy part! SQL Tools Standard is priced at just $99.95, while the Pro Version is $199.95. So please don't wait... you can purchase right on the PowerBASIC Web Site. GOTO www.powerbasic.com -- PURCHASE ==================================================================== All contents Copyright (c) 2009 PowerBASIC Inc All Rights Reserved. PowerBASIC, PB/CC, PB/DLL, PowerGEN, and PowerTREE are trademarks of PowerBASIC Inc. Other names are trademarks or registered trademarks of their owners. ==================================================================== PowerBASIC Gazette - Electronic Edition Volume 1 - Issue 68 Visit us on the World Wide Web at www.powerbasic.com Email Sales: sales@powerbasic.com This newsletter is only sent to email addresses in our subscription list. If you have received this newsletter by mistake or no longer wish to receive it, please send a simple unsubscribe request to support@powerbasic.com with your name and zip/postal code. This newsletter is best viewed with a fixed-width font. ====================================================================