Perdón, al hacer vista previa de mensaje, el código delphi se veía bien, pero al enviar la respuesta definitiva me lo formatea mal.
Vuelvo a enviar el código delphi formateado:
Código Delphi
[-]
procedure TMDOSQL.Prepare;
var
stmt_len: Integer;
res_buffer: array[0..7] of Char;
type_item: Char;
begin
if FCursor = '' then
FCursor := Name + RandomString(8);
CheckClosed;
FBase.CheckDatabase;
FBase.CheckTransaction;
if FPrepared then
exit;
if (FSQL.Text = '') then
MDOError(mdoeEmptyQuery, [nil]);
if not ParamCheck then
FProcessedSQL.Text := FSQL.Text
else
PreprocessSQL;
if (FProcessedSQL.Text = '') then
MDOError(mdoeEmptyQuery, [nil]);
try
Call(isc_dsql_alloc_statement2(StatusVector, DBHandle,
@FHandle), True);
Call(isc_dsql_prepare(StatusVector, TRHandle, @FHandle, 0,
PChar(FProcessedSQL.Text), Database.SQLDialect, nil), True);
type_item := Char(isc_info_sql_stmt_type);
Call(isc_dsql_sql_info(StatusVector, @FHandle, 1, @type_item,
SizeOf(res_buffer), res_buffer), True);
if (res_buffer[0] <> Char(isc_info_sql_stmt_type)) then
MDOError(mdoeUnknownError, [nil]);
stmt_len := isc_vax_integer(@res_buffer[1], 2);
FSQLType := TMDOSQLTypes(isc_vax_integer(@res_buffer[3], stmt_len));
case FSQLType of
SQLGetSegment,
SQLPutSegment,
SQLStartTransaction: begin
FreeHandle;
MDOError(mdoeNotPermitted, [nil]);
end;
SQLCommit,
SQLRollback,
SQLDDL, SQLSetGenerator,
SQLInsert, SQLUpdate, SQLDelete, SQLSelect, SQLSelectForUpdate,
SQLExecProcedure: begin
if (FSQLParams.FXSQLDA <> nil) and
(Call(isc_dsql_describe_bind(StatusVector, @FHandle, Database.SQLDialect,
FSQLParams.FXSQLDA), False) > 0) then
MDODatabaseError;
FSQLParams.Initialize;
if FSQLType in [SQLSelect, SQLSelectForUpdate,
SQLExecProcedure] then
begin
FSQLRecord.Count := 1;
Call(isc_dsql_describe(StatusVector, @FHandle, Database.SQLDialect, FSQLRecord.FXSQLDA), True);
if FSQLRecord.FXSQLDA^.sqld > FSQLRecord.FXSQLDA^.sqln then
begin
FSQLRecord.Count := FSQLRecord.FXSQLDA^.sqld;
Call(isc_dsql_describe(StatusVector, @FHandle, Database.SQLDialect, FSQLRecord.FXSQLDA), True);
end else if FSQLRecord.FXSQLDA^.sqld = 0 then
FSQLRecord.Count := 0;
FSQLRecord.Initialize;
end;
end;
end;
FPrepared := True;
if not (csDesigning in ComponentState) then
MonitorHook.SQLPrepare(Self);
except
on E: Exception do
begin
if (FHandle <> nil) then
FreeHandle;
raise;
end;
end;
end;
Disculpad.