ClassPath: MEng.System.Runtime.DBStatement Parent ClassPath: MEng.Object Copyable: No Final: Yes MEng.System.Runtime.DBStatement provides read and write access to ODBC databases. It is used in conjunction with the DBConnect class. DBConnect establishes a connection to a database, and you will pass the DBConnect object to your DBStatement object and it will work in terms of that database connection.
The statement class allows you to set up 'column bindings', effectively defining the columns of the table that you are expecting to get back from read operations or to send in write operations. It is up to you to correctly define the columns to match the data in the SQL statements you ask this statement object to execute. If not, you will get errors.
You can reset the object and re-load new column bindings to do a different query. Normally, if you are doing repetitive database operations, you'd just want to set up separate statement operations for the various types of SQL statements that you need to do, go avoid having to do this. You use the Fetch operation to pull successive rows of a query into your column bindings and then you can read out the columns for that row.
Nested Classes:
Enum=DBStmtErrors AddBindingErr : ""; ExecErr : ""; FetchErr : ""; GetColErr : ""; GetNameErr : ""; NotReady : "The statement has not been initialized yet"; Reset : ""; EndEnum;This enumerated type provides the errors that this class can throw. Some of them don't have any text since they are just assigned the text of the underlying C++ error that caused them.
Enum=DBColTypes Boolean : "Boolean"; Card1 : "Card1"; Card2 : "Card2"; Card4 : "Card4"; Card8 : "Card8"; Date : "Date"; Int1 : "Int1"; Int2 : "Int2"; Int4 : "Int4"; String : "String": Time : "Time"; EndEnum;This enumerated type defines the data types that can be bound to a column for a read or write operation.
Constructors:
Constructor(); Constructor([In] DBConnect ConnToUse, [In] String Name);There is a default constructor available, which will require a subsequent call to Reset() to set it up for use. There is also a constructor that takes the information required to set it up for use. You can still call Reset() again later to set it up for another connection. In the second constructor you pass a connection object and a name to give this object. This identifies the statement object and usually indicates something about what it is used for, like Payroll or whatnot.
Final, Const Methods:
GetName() Returns MEng.String;Returns the name of this statement object, as set in the constructor or Reset() methods.
Final, Non-Const Methods:
AddBinding([In] MEng.String ColName, [In] DBColTypes Type); AddStrBinding([In] MEng.String ColName, [In] MEng.Card4 MaxChars);These methods add column bindings. The SQL statement is assumed to produce (or expect if writing) columns in the order that they are added using these methods. There is a separate method for string bindings so that you can set the maximum string size for the string column. If an error occurs, then an AddBindingErr exception will be thrown
Execute([In] MEng.String SQLStatement);Executes the SQL statement indicated. If it is a read (SELECT) operation, then the columns returned will be placed into your defined column bindings as you call Fetch. If the SQL statement fails, then an ExecErr exception will be thrown.
Fetch() Returns MEng.Boolean;Fetches the next row of a SELECT into your column bindings, which you can pull out using the GetXXXCol() methods below. It will return False when no more rows are available. If an error occurs, the FetchErr exception will be thrown.
GetBoolCol([In] MEng.Card4 Index) Returns MEng.Boolean; GetCard1Col([In] MEng.Card4 Index) Returns MEng.Card1; GetCard2Col([In] MEng.Card4 Index) Returns MEng.Card2; GetCard4Col([In] MEng.Card4 Index) Returns MEng.Card4; GetCard8Col([In] MEng.Card4 Index) Returns MEng.Card8; GetDateCol([In] MEng.Card4 Index) Returns MEng.Time; GetInt1Col([In] MEng.Card4 Index) Returns MEng.Int1; GetInt2Col([In] MEng.Card4 Index) Returns MEng.Int2; GetInt4Col([In] MEng.Card4 Index) Returns MEng.Int4; GetStrCol([In] MEng.Card4 Index) Returns MEng.String;These methods will retrieve the value from a column. After you do a SELECT operation, you call Fetch repeatedly to get each successive row into the column bindings, and then you can call these methods to get the column values out. You indicate which column by index (zero based, in the order that they were added) and that column must be of the type for the version of this method that you call. If an error occurs, the GetColErr exception will be thrown.
Reset([In] DBConnect ConnToUse, [In] String Name);This method will reset this object to a new database connection and name. All column bindings will be removed so you will need to re-add any needed column bindings for the new use.