Determine the data type of parameters in a parameterized query using Zeoslib

Is it possible to determine the data type of parameters in a parameterized query using Zeoslib and Firebird?

I am transitioning from FibPlus to Zeoslib.

with words like "select first name, last name, age from members, where is registration>: since then and nationality =: country"

With FibPlus, I do this:

  for i := 0 to Q1.Params.Count - 1 do
  begin

    t := Q1.Params[i].ServerSQLType;

    case t of
      SQL_TYPE_DATE, SQL_TYPE_DATE + 1:
        begin
          with TsDateEdit.Create(self) do
          begin
            Left := lblleft + MaxWidth + 10;
            Top := lbltop + (25 * i) - (height - LabelHeight);
            Parent := f;
            Tag := i + 1;
            TabOrder := i;
          end;
        end;
      sql_short, sql_long, sql_int64, sql_short + 1, sql_long + 1, sql_int64 + 1:
        begin
          with TsSpinEdit.Create(self) do
          begin
            Left := lblleft + MaxWidth + 10;
            Top := lbltop + (25 * i) - (height - LabelHeight);
            Parent := f;
            Tag := i + 1;
            TabOrder := i;
          end;
        end;
....

With Zeoslib, I tried this:

  for i := 0 to Q1.Params.Count - 1 do
  begin

    if Q1.Params[i].DataType = ftDate then
        begin
          with TsDateEdit.Create(self) do
          begin
            Left := lblleft + MaxWidth + 10;
            Top := lbltop + (25 * i) - (height - LabelHeight);
            Parent := f;
            Tag := i + 1;
            TabOrder := i;
          end;
        end;

    if Q1.Params[i].DataType in [ftInteger, ftShortInt, ftLargeInt, ftLongWord] then
        begin
          with TsSpinEdit.Create(self) do
          begin
            Left := lblleft + MaxWidth + 10;
            Top := lbltop + (25 * i) - (height - LabelHeight);
            Parent := f;
            Tag := i + 1;
            TabOrder := i;
          end;
        end;
....

but Q1.Params [i]. The data type is always available.

+4
source share
1 answer

You cannot do this with strollers because they are not installed at the moment. I suggest you use TZSQLMetadata;

  ZSQLMetadata1 := TZSQLMetadata.Create(Self);
  try
    ZSQLMetadata1.Connection := ZConnection1; //Your connection to db
    ZSQLMetadata1.MetadataType := mdColumns; //What kind of meta data get you want column types so we get columns metadata
    ZSQLMetadata1.TableName := 'MYTABLE'; //from which table metadata to get
    ZSQLMetadata1.Open;

    //After open ZSQLMetadata1 rows contains information about table columns
    while not ZSQLMetadata1.Eof do
    begin
      if ZSQLMetadata1.FieldByName('TYPE_NAME').AsString = 'char' then
      begin
        //Do something
      end;

      { if you do not like working with strings
      if ZSQLMetadata1.FieldByName('DATA_NAME').AsInteger = 9 then
      begin
        //Do something
      end;
      }   
      ZSQLMetadata1.Next;
    end;
  finally
    ZSQLMetadata1.Free;
  end;

ZSQLMetadata1 , , datasource dbgrid

// - , - MySQL

+2

Source: https://habr.com/ru/post/1611079/


All Articles