DescribeCursor: IDalCursor;
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.
Executing the example requires a form, a button with the Button1 identifier on this form and the Memo component with the Memo1 identifier. A database with the DB identifier must also be in the repository. The given macro should be set as the OnClick event handler for the button.
Click the button to start executing the example.
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(Null) As IDatabaseInstance;
DalComm := DB_Inst.Connection.CreateCommand(sql);
Try
DalCur := DalComm.DescribeCursor;
MObj.Save;
WinApplication.InformationBox("Query was created");
DalCur.Close;
Except
WinApplication.InformationBox("There is an error in the query text");
End Try;
DalComm.Close;
End Sub Button1OnClick;
Query with the text specified in the Memo1 component is created in the repository after executing this example. If there is an error in the query text, the information message is displayed. The query is not created.
See also: