TSYBSql Component

 

Derived from TComponent

 

Overview:

 

This is the second component required for use with any of the other Sybase database components.  It uses the data-stream provided by the TSybDatabase  component. It’s main function is to provide a method of sending SQL statements to the server and to route the result-set to suitable components on the form.  It differs from commercial components in that it works with all of Borland’s standard data components. TSYBSql can use any of the following, as well as components derived from them.

 

TLabel

TEdit

TCustomMemo

TCustomListBox

TCustomComboBox

TStringGrid

 

In addition to the above six visual components, TSYBSql can also use the following two non visual components for storing data.

 

TSybArray

TSybVariable

 

This process is automated in that the TSYBSql component will search the form for any components whose name matches the name of the columns in the result set.  If it finds a match, the TSYBSql component will identify the matching component type and populate that component with the results from the matching column in the result set.  Component names can be dynamically changed at run-time to match column names, or column names can be aliased to match the component name. 

 

The only exception to this rule is the TStringGrid component whose name does not have to match any column names.  To use a TStringGrid component to hold a result set, you have to insert column names ( or names to alias to) in the first row of the String Grid.  This is where you would usually place column labels for your grid, so TSYBSql will search any TStringGrid’s on your form and see if it finds any matching columns.  If it does find one or more matches, then the relevant result set data will be populated to those columns in the grid.

 

Note:  If you have more than one component/column with the same name, TSYBSql will use the first one it finds and ignore the others with the same name.

 

Events are provided for user supplied error messages, should the user not want to use the default error messages.  (Useful for foreign languages).  A SQL dialog box is provided at design-time for entering SQL text.  At run-time you should add your SQL dynamically, prior to calling the execute method.  See the Project1 example.

 

Properties:

CancelMessages

If true then no runtime error messages will be displayed.  Users should then use the relevant events to write their own error messages.

Name

The component Name.

Tag

User available integer.

_DatabaseObject

Set this to the name of the TSybDatabase component which you will be using as connection to Sybase

_Execute

Set this to true to execute your SQL statements. 

You can also call the method directly e.g. SybSQL1->Execute();

_SQL

At design-time, click this property to open a dialog which allows you to enter SQL statements.  At run-time, add sql statements to the SQL StringList as in the example below:

 

SybSQL1->SQL->Clear();

SybSQL1->SQL->Add("select country ONE, p_code TWO, id_type THREE from country ");

 

Events:

OnAfterQuery

Called once the complete result set of a query has been returned successfully.

OnBeforeQuery

Called just prior to the result set being returned from Sybase.

OnDBNoProcess

Called if an ‘execute’ was attempted but no running TSYBDatabase datastream was found.  The default error message is

 "No running DB process found"

OnExecuteFail

Called when TsybSql tried to execute some SQL statements, but Sybase returned an error message.  The default error message is

 " Could not execute dbsqlexec with given SQL statements"

OnLoadSQLFail

Called if an error occurred when trying to load the buffer with the users SQL statements.  .  The default error message is

 " Error loading SQL"

OnMissingDBObject

Called if you attempt to use TsybSql without first placing a TSybDatabase component on the form.  The default error message is

 " No TSybaseDataBase objects have been placed yet "

 

Public variables and methods

void __fastcall Execute()

Executes the SQL statements.  Same as setting _Execute property to true.

DBPROCESS *dbproc

Pointer to the active db process.  Used by most other db-library calls.

AnsiString          DatabaseObject

Run-time variable which points to the TSybDatabase component which TSybSql is currently using.  You can use and swop TSybDatabase components at runtime e.g. to call rpc’s on two different Sybase servers.  At design-time, use the _DataBase property to set this variable.

TStringList         *SQL

Add your runtime-time sql statements here, as in the _SQL example above..

int                 column_count

Consider as Read-only.  Do not write to this because the execute method will automatically overwrite this variable with the number of columns returned by the result set.