IDalCommand.DescribeCursor

Syntax

DescribeCursor: IDalCursor;

Description

The DescribeCursor method creates a cursor, which contains only data fields. If there is an error in the text of the SQL query to the database, the exception is thrown. This method can be used to control the correctness of queries.

Example

Executing the example requires a form that contains the Button component with the Button1 identifier and the Memo component with the Memo1 identifier. The repository must also contain a database with the DB identifier. The example is a handler of the OnClick event for the Button1 component.

Add links to the Collections, Dal, Db, ExtCtrls, Forms, Metabase, and Ui system assemblies.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    MB: IMetabase;
    CrInf: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Query: IQuery;
    DB_obj: IMetabaseObject;
    DB_Inst: IDatabaseInstance;
    DalComm: IDalCommand;
    sql: String;
    DalCur: IDalCursor;
Begin
    MB := MetabaseClass.Active;
    CrInf := Mb.CreateCreateInfo;
    CrInf.ClassId := MetabaseObjectClass.KE_CLASS_QUERY;
    CrInf.Id := "NEW_QUERY";
    CrInf.Name := "NEW_QUERY";
    CrInf.Parent := Mb.Root;
    MObj := Mb.CreateObject(CrInf).Edit;
    Query := MObj As IQuery;
    DB_obj := Mb.ItemById("DB").Bind;
    Query.Database := DB_obj As IDatabase;
    sql := Memo1.Text;
    Query.Sql := sql;
    DB_Inst := DB_obj.Open(NullAs IDatabaseInstance;
    DalComm := DB_Inst.Connection.CreateCommand(sql);
    Try
        DalCur := DalComm.DescribeCursor;
        MObj.Save;
        WinApplication.InformationBox("Query created");
        DalCur.Close;
        Except
            WinApplication.InformationBox("Query text contains error");
    End Try;
    DalComm.Close;
End Sub Button1OnClick;

After executing the example a query with the text specified in the Memo1 component is created in the repository. If there is an error in the query text, the information message is displayed. The query is not created.

See also:

IDalCommand