There is an IBExtract component, it allows you to retrieve the database metadata (tables, procedures, triggers ...) as a script. Here is a sample code that retrieves data from a TABLE table.

IBExtract.ExtractObject(eoData, 'TABLE'); IBExtract.Items.SaveToFile('d:\123.ddl'); 

But I need to save not all the data but a certain part of the condition. Of course, you can run a query on a dataset, generate a script and save it to a file. Maybe there is still some opportunity to upload data by condition to the script?

  • one
    IMHO, the easiest way is to execute the query, run through the result and form a script. - KiTE

1 answer 1

If you are not bothered to edit the source, then you can add the ListData procedure in the way you want. Or write your own export implementation, something like this (I did not check it myself, there is no suitable base at hand):

 uses ... IB, IBDatabase, IBHeader, IBSQL, IBUtils ... function MyListData(const Database: TIBDatabase; const ObjectName: string; const Filter: string = ''): string; const SelectSQL = 'SELECT * FROM %s'; {do not localize} WhereClause = ' WHERE (%s)'; {do not localize} var qrySelect: TIBSQL; FieldName, Fields, Values, DateStr: string; i: Integer; begin qrySelect := TIBSQL.Create(Database); try qrySelect.SQL.Text := Format(SelectSQL, [QuoteIdentifier(Database.SQLDialect, ObjectName)]); if Filter <> '' then qrySelect.SQL.Text := qrySelect.SQL.Text + Format(WhereClause, [QuoteIdentifier(Database.SQLDialect, Filter)]); qrySelect.ExecQuery; Fields := ''; for i := 0 to qrySelect.Current.Count - 1 do if (qrySelect.Fields[i].SQLType <> SQL_ARRAY) and (qrySelect.Fields[i].SQLType <> SQL_BLOB) and (not Database.Has_COMPUTED_BLR(ObjectName, qrySelect.Fields[i].Name)) then begin FieldName := String(qrySelect.Fields[i].SQLVAR.sqlname); if Fields <> '' then Fields := Fields + ', '; {do not localize} Fields := Fields + QuoteIdentifier(Database.SQLDialect, FieldName); end; while not qrySelect.Eof do begin Result := 'INSERT INTO ' + QuoteIdentifier(Database.SQLDialect, ObjectName) + ' ('; {do not localize} Result := Result + Fields + ') VALUES ('; {do not localize} Values := ''; for i := 0 to qrySelect.Current.Count - 1 do begin if (Values <> '') and (qrySelect.Fields[i].SQLType <> SQL_ARRAY) and (qrySelect.Fields[i].SQLType <> SQL_BLOB) then Values := Values + ', '; if qrySelect.Fields[i].IsNull and (qrySelect.Fields[i].SQLType <> SQL_ARRAY) and (qrySelect.Fields[i].SQLType <> SQL_BLOB) then begin Values := Values + 'NULL'; {do not localize} end else case qrySelect.Fields[i].SQLType of SQL_TEXT, SQL_VARYING : Values := Values + QuotedStr(qrySelect.Fields[i].AsTrimString); SQL_TYPE_DATE : begin DateTimeToString(DateStr, 'mm/dd/yyyy', qrySelect.Fields[i].AsDate); Values := Values + QuotedStr(DateStr); end; SQL_TYPE_TIME : begin DateTimeToString(DateStr, 'hh:mm:ssss', qrySelect.Fields[i].AsTime); Values := Values + QuotedStr(DateStr); end; SQL_TIMESTAMP : begin DateTimeToString(DateStr, 'mm/dd/yyyy hh:mm:ssss', qrySelect.Fields[i].AsDateTime); Values := Values + QuotedStr(DateStr); end; SQL_SHORT, SQL_LONG, SQL_INT64, SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT: Values := Values + qrySelect.Fields[i].AsTrimString; SQL_ARRAY, SQL_BLOB : ; else IBError(ibxeInvalidDataConversion, [nil]); end; end; Result := Result + Values + ')' + ';'#13#10;//Term; {do not localize} qrySelect.Next; end; finally qrySelect.Free; end; end; 
  • Damn, there was a typo - corrected. Example usage: <br> Memo1.Text: = MyListData (IBDataBase1, 'TABLE', 'Field3 = 48'); - toxicdream
  • one
    Thanks for the help, also came to this conclusion, just did not want to reinvent the wheel. Your code did not check, I will rewrite the standard from IBExport module for my own, so to speak, needs. - Timenzzo