#1 2021-10-15 22:23:23

Daniel_Andrascik
Member
Registered: 2013-07-11
Posts: 9

TSqlDBOleDBStatement - get RawColumnTypes (mORMot2)

Hello

I use yours MSSQL OLE DB driver. Only driver i.e. ISqlDBRows and ISqlDBStatement, not ORM. But sometimes I need to get raw MS SQL column types. I parsed your code until late at night and i created the following function (i still have a little headache from it):

type
  TSqlDBOleDBStatementHack = class(TSqlDBOleDBStatement);
  TSqlDBOleDBConnectionHack = class(TSqlDBOleDBConnection);

function TmORMotOLEDBBaseAdapter.GetRawColTypes(const aRS: ISqlDBRows): TArray<WORD>;
var
  DBStat: TSqlDBStatement;
  DBOLEStat: TSqlDBOleDBStatementHack;
  Conn: TSqlDBConnection;
  Cols, nfo: PDBColumnInfo;
  nCols: PtrUInt;
  ColsNames: PWideChar;
  i: Integer;
begin
  DBStat := aRS.Instance;
  if DBStat is TSqlDBOleDBStatement then
  begin
    SetLength(Result,aRS.ColumnCount);
    DBOLEStat := TSqlDBOleDBStatementHack(TSqlDBOleDBStatement(DBStat));
    TSqlDBOleDBConnectionHack(DBOLEStat.OleDBConnection).OleDBCheck(DBStat,(DBOLEStat.fRowSet as IColumnsInfo).GetColumnInfo(nCols, Cols, ColsNames));
    try
      nfo := Cols;
      for i := 1 to nCols do
      begin
        Result[i-1] := nfo^.wType;
        inc(nfo);
      end;
    finally
      TSqlDBOleDBConnectionHack(DBOLEStat.OleDBConnection).fMalloc.Free(Cols);
      TSqlDBOleDBConnectionHack(DBOLEStat.OleDBConnection).fMalloc.Free(ColsNames);
    end;
  end;
end;

This is the right and best way to achieve the right result?

Daniel Andrascik

Offline

#2 2021-10-16 09:44:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TSqlDBOleDBStatement - get RawColumnTypes (mORMot2)

I have just enhanced TSqlDBOleDBStatement to let TSqlDBColumnProperty.ColumnValueDBType store the raw DBTYPE value.
I guess this is the more convenient and safe way of getting this information.

Check https://github.com/synopse/mORMot2/comm … 6a9dc1f53d
and https://github.com/synopse/mORMot2/commit/cda6b213d6

Offline

#3 2021-10-16 21:28:25

Daniel_Andrascik
Member
Registered: 2013-07-11
Posts: 9

Re: TSqlDBOleDBStatement - get RawColumnTypes (mORMot2)

Great work... wink

Offline

Board footer

Powered by FluxBB