Presentation is loading. Please wait.

Presentation is loading. Please wait.

Looking at your data in a New Way

Similar presentations


Presentation on theme: "Looking at your data in a New Way"— Presentation transcript:

1 Looking at your data in a New Way
A look at ODBC and SQL

2 What is ODBC? Open DataBase Connectivity is an open standard application programming interface (API) for accessing a database. ODBC requires a specific driver for each type of database to be accessed. ODBC is based on, and closely aligned with Structured Query Language (SQL) Call-Level Interface. It allows programs to use SQL requests to access databases without having to know the proprietary interface of the databases. ODBC handles the SQL request and converts it into a request the individual database system understands.

3 What is SQL? Structured Query Language is used to communicate with a relational database. The language is driven by a small group of keywords. While the implementation with each Database Management System (DBMS) varies, the basic SQL language is governed by ANSI standards. Some DBMS environments may extend or limit functionality.

4 What SQL is NOT! While many associate SQL with the Microsoft SeQueL product, Sequel is a clever name selected by Microsoft for their implementation of DBMS software. The use of the SQL language does not imply use of Microsoft Sequel Database.

5 What is a DBMS? The DataBase Management System is actually a software implementation. A database is the “container” - a collection of data stored in a logical manner. A database is made up of tables that contain columns and rows (fields and records to some of us). Unlike most DataBase Management Systems, BR stores files individually. A DBMS typically stores the tables, schema, and other elements in a single file.

6 Introducing our Textbook
After reviewing several books, I selected the book by Ben Forta for its balanced and reasonable introduction to SQL. Many books on the subject delve into too much detail on the theory of databases, architecture, etc. Our text, “Teach yourself SQL in 10 minutes” is a balanced concise introduction to SQL that will allow you to use the BR ODBC interface.

7 End of Introduction

8 Retrieving a Dataset The SELECT statement identifies the columns to be retrieved from the various tables within the database. All SELECT statements are composed of 3 parts The keyword SELECT followed by the names of columns to be made a part of the dataset (“*” indicates all columns). This is not considered to be secure and will be discussed in the presentation The table name(s) that contain these columns Conditions for inclusion This is expressed as: “SELECT (column names) from TABLE where column-name (conditions) value”

9 Simple “SELECT” statement
Example: Select debtclmn, debtcomp from claimsfile where debtcomp = '891735'

10 “conditions” may be used in Select Statement
The obvious conditions compare columns to exact values (totdue>500). These include equal to (=), greater than (>), less than (<), etc. Other types of conditions include “containing” or “like”. “Like” searches the column value using wildcards, while “containing” searches the entire value for the occurrence of the text. Just as the select statement may include multiple columns, multiple conditions may be used to select the dataset.

11 Selecting Data To select all claims “containing” the word Advertise: Select debtclmn,debtname from claimsfile where upper(debtname) containing 'ADVERTISE'

12 Sorting the Dataset The phrase “order by” column(s) is appended to the select statement of the previous example to sort the output. Note that the word “desc” following the column indicates descending.

13 A more complex example Building on the previous example, lets add more columns and more conditions, while renaming the columns!

14 Another twist.. Changing the “order” allows you see that the upper limit of the amount is truly

15 Creating a calculated field
The actual balance value is not explicitly part of the data, but instead is calculated from the sum of several other fields. A new column can be created for this value....

16 Functions within SQL There are a variety of functions that may be incorporated in an SQL statement. These vary between DBMSs and the result is that some statements are not portable. Text or character functions include Left() Length() Ltrim() and Rtrm() Upper() demonstrated in previous examples And many more... Mathematic functions exist as well Date and Time calculations Absolute value Avg, Count, Max, Min etc.

17 Combining data from more tables
A JOIN combines data from multiple tables, so you can see the status of claims in my previous example.

18 Using the INNER JOIN syntax
This is an INNER JOIN and is the only join supported by the BR ODBC driver. Note the variation of the SQL command. A brief discussion of other joins appears in chapter 13 of the text.

19 Using Alias Table Names
The use of alias table names significantly shortens the SQL command as shown below.

20 SQL in Review SQL has additional functions not discussed to create a Table, alter a Table structure, add a column, create indexes for faster access, and to write/update data in the files. The BR ODBC interface is READ-ONLY! As such, these commands do not apply. For a complete understanding of these commands, refer to our Textbook. Finally, while it is good to know how to structure these commands, there are some graphical design tools (drag and drop) that allow you to generate an SQL command. Since all “versions” are not identical in the implementation, it may be necessary to work with the exact command before it will work in another application using SQL.

21 End of SQL Presentation, Luis will present using SQL with commercial applications (Excel, etc.)

22 Using ODBC in your programs
BRODBCGRID is an external executable program that allows you to execute a properly prepared SQL statement from within your BR program. It displays the resulting dataset in a grid. Written in Delphi, the program depends upon a text file for execution. Since the BR shell call has a maximum length, all “switches” to configure this program must be written to a control file. This avoids the problem with a long text string such as the SQL query. Write one switch per line as “dash” “switch” “value”. To specify the caption: “-CSample BR Grid”

23 Using ODBC in your programs
BRODBCGRID.exe documentation appears in the conference manual and as an RTF file on your flash drive. Features exist to allow cell level editing, but validation and update of the BR file is dependent on the BR application. (This is purposefully NOT documented, see me if you have any interest in this project.) If this utility is implemented by you (or myself), I may expand the available options. Once the control file is built, the grid is displayed using a BR shell call. The shell call consists of the fully qualified path to the executable and the fully qualified path of the control file. By default the results are written to the location of the exe. See the -B explanation for more detail. 00010 execute "sys -w C:\brag_conference\spring_2008\BrodbcGrid.exe -#C:\brag_conference\spring_2008\payroll_query.txt”

24 Create the “control file”
(For purposes of showing the complete query, it is “wrapped”. In the actual file this must be on one line as each line is interpreted as one “switch”.) -B011 -CTest DBGrid for ADS -Accffcc -N10 -DApplication=PAYROLL|File=DEDUCT -QSELECT DEDUCT.CO_NUM, DEDUCT.DEDUCT_TYPE, EMPLOYEE.CO_NUM, EMPLOYEE.EMP_NAME FROM DEDUCT DEDUCT, EMPLOYEE EMPLOYEE WHERE DEDUCT.CO_NUM = EMPLOYEE.CO_NUM file”

25 Adding Distinct to the Query
-B011 -CTest DBGrid for ADS -Accffcc -N10 -DApplication=PAYROLL|File=DEDUCT -QSELECT DISTINCT DEDUCT.CO_NUM, DEDUCT.DEDUCT_TYPE, EMPLOYEE.CO_NUM, EMPLOYEE.EMP_NAME FROM DEDUCT DEDUCT, EMPLOYEE EMPLOYEE WHERE DEDUCT.CO_NUM = EMPLOYEE.CO_NUM

26 Shortened Query, changed Caption
-B011 -CSpring 2008 Sample Grid -Accffcc -N10 -DApplication=PAYROLL|File=DEDUCT -QSELECT DISTINCT D.CO_NUM, D.DEDUCT_TYPE, E.CO_NUM, E.EMP_NAME as "Employee Name" FROM DEDUCT D, EMPLOYEE E WHERE D.CO_NUM = E.CO_NUM Notice the shorter syntax using a single letter alias (D and E), the column name “Employee Name”, and the changed caption.

27 Print or Save the data

28 Conclusions The results can be printed, written to a file of the user's choosing, or interpreted by your program for additional processing. The saved file can be copied to a specific path and name that your user specifies (via your application). Use FILEDIALOG.exe to provide a window's file selection! Many times a set of selected records (CSV) sent to a spreadsheet by another shell call, or a printed report is all that is required.

29 Thank you for your time. If you have specific questions regarding implementation of BRODBCGRID in your application, or questions about it's use, I would be happy to discuss them with you. This grid can be made to work with any ODBC interface. The only issue is creating and passing the correct connection string. The string is currently fixed for BR ODBC implementation. The -D switch provides the parameters necessary to build this string. As we move forward with the rest of the Spring conference, let me encourage each of you to take an active part in future conferences. The strength of the BR Group is in participation!


Download ppt "Looking at your data in a New Way"

Similar presentations


Ads by Google