#1 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-02-15 01:23:12

ab wrote:

@gunix
Which version of Delphi are you using?

Edit: my guess is that it is FPC/Lazarus.
I have committed a huge refactoring for better Lazarus compatibility of the mormot.db.rad.*.pas units.

Fpc 3.3.1, lazarus 3.6

largeintfield  set filter  error reported freepascal.org forum

create table testtable(prjid int8 primary key,prjname varchar(20),address varchar(64),telephone varchar(12));
INSERT INTO testtable ("prjid", "prjname", "address", "telephone") VALUES (3556856671915480078, '华泰大夏', NULL, NULL);
INSERT INTO testtable ("prjid", "prjname", "address", "telephone") VALUES (3566802869275333664, '盛世钱门', '', '17706555935');

var
  i:integer;
  FDBCOnnect:TSqlDBConnectionProperties;
  FPData:TsqlDataset;
begin
  FDBCOnnect:=TSqlDBPostgresConnectionProperties.Create('0575.tech:5432','test','test','test123');
  FPData:=TsqlDataset.Create(self);
  FPData.Connection:=FDBCOnnect;
  FPData.CommandText:='select * from testtable';
  FPData.Open;
  showmessage('address size='+inttostr(FPData.fieldbyname('address').Datasize));
  while not FPData.EOF do begin
    showmessage(inttostr(FPData.RecNo)+'row prjname='+ FPData.FieldByName('prjname').AsWideString);
    FPData.Next;
  end; 

#2 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-02-14 09:27:07

lfyey121 wrote:

I solved this problem by defining the fields of the dataset directly at design time

It's mistake,I should use TsqlDataset
but all null value widestring field the size will be  0   in TsqlDataset
TVirtualDataSet.GetFieldData to get widestring value will rise exception when value is chinese words  like '测试中文' (fieldsize=12)


change     
    Utf8ToWideString(data, len, WideString(dest^));   

to
         if len = 0 then
            PWideChar(dest)^ := #0
         else
           Utf8ToWideChar(dest, data, Field.DataSize, len);   
can display right value

largeInt  field   set  filter   is  Ineffective

#3 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-11 14:17:10

unidac can Get field size, string field.size =character_octet_length
pq.fsize always return  -1
when client app commit data to server, raise error "value is too long(20)" when insert more than 20 character ( fiedtype=varchar(20)),so, Give a permit length is a good idea in client side.


I have test ,Can't work right

procedure TSqlDBPostgresStatement.BindColumns;
var
  nCols, c,k: integer;
  cName: RawUtf8;
  p: PUtf8Char;
begin
  ClearColumns;
  nCols := PQ.nfields(fRes);
  fColumn.Capacity := nCols;
  for c := 0 to nCols - 1 do
  begin
    p := PQ.fname(fRes, c);
    FastSetString(cName, p, StrLen(p));
    with AddColumn(cName)^ do
    begin
      ColumnAttr := PQ.ftype(fRes, c);
      ColumnType := TSqlDBPostgresConnectionProperties(Connection.Properties).
        Oid2FieldType(ColumnAttr);
      //add
      ColumnDataSize:=PQ.fsize(fRes, c);
    end;
  end;
end;

#4 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-10 09:16:49

then,why FieldDefs need set field size of string field? 
DBgrid Can Adjust Column width by Field size?

also I can set field size to   -1

#5 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-10 08:40:00

fsize :: Result
      -> Column
      -> IO Int
fsize result (Col colNum) = numFromResult result $ \ptr -> c_PQfsize ptr colNum;

Can Use fsize function in libpq.dll  get field size  on Postgresql DBMS?

if Can get field size ,the unit can be UTF-8 bytes

#6 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-10 06:28:59

zen010101 wrote:

You can try the TSqlDBConnectionProperties.GetFields() method ab mentioned. This method outputs the field definition to the Fields parameter, which is a TSqlDBColumnDefineDynArray type. Each element contains the following information:

I don't know Field from which Table,because I read Sql from Json File,   Fetch Data,Display Data.

#7 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-09 22:02:01

in order to convert into Delphi TDataset, FieldDefs.Add( FieldName,FieldType,FieldSize,CanNull)

#8 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-09 09:45:49

SqlStatement:TSqlDbStatement;

SqlStatement.Execute('select A.F1,A.F2,...... from Test A join xxx B  on A.xxx=B.xxx where .....');
ColumnType(0) Can Get F1 FieldType ftUtf8, But i don't know how to get field size

#9 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-09 08:30:02

ab wrote:

What do you call "field size" then?

create table Test (F1 char(20), F2 varchar(10));
insert into Test(F1,F2) Values('F1 Test Value','Should ok')

How Can I get F1 Field Size=20 and F2 Field size=10?

#10 Re: mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-09 02:58:22

ab wrote:

You have ISqlDBRows.ColumnNull() for this.
For the field size, use ColumnUtf8() and its returned length.

    function ColumnUtf8(Col: integer): RawUtf8;
ColumnUtf8 can't get field size, only return empty string

#11 mORMot 2 » How Can I Get Column FieldSize when I Use TSQLDBStatement Get ReCord? » 2025-01-08 10:13:11

gunix
Replies: 22

i Should know the size of Character field, and Whether or not field can be null?

#12 Re: mORMot 2 » There may be Error in ProcessStaticFile of Net.server.pas [solved] » 2023-07-14 01:13:16

ab wrote:

I am not sure I understand what you meant, sorry.

Do you mean that your callback should return result = 200 so that it works as expected?
So is it solved?

Yes

#13 Re: mORMot 2 » There may be Error in ProcessStaticFile of Net.server.pas [solved] » 2023-07-13 07:09:15

I See,  OnRequest call back shoud return HTTP_SUCCESS
OnRequest(Ctxt: THttpServerRequestAbstract): cardinal;   
begin
    Result:=HTTP_FOUND;         //default return value
   Ctxt.OutContentType:=TEXT_CONTENT_TYPE;   
   if StartWith(Ctxt.Url, uppercase('/upgradefile/')) then  begin
      Ctxt.OutContentType:=STATICFILE_CONTENT_TYPE; 
      ctxt.OutContent:=StringToUtf8('xxxxxxx');
      ctxt.RespStatus:= HTTP_SUCCESS;                                                      ==>   Result:=HTTP_SUCCESS;
   end

end;

#14 mORMot 2 » There may be Error in ProcessStaticFile of Net.server.pas [solved] » 2023-07-13 06:46:19

gunix
Replies: 3

if Context.ContentFromFile(fn, CompressGz) then
        OutContent := Context.Content                             ==>   fRespStatus := HTTP_SUCCESS              outContent  no need
      else
      begin
        FormatString('Impossible to find %', [fn], fErrorMessage);
        fRespStatus := HTTP_NOTFOUND;
      end;


follow :
  Context.Content := OutContent;                             ==>      if not ((OutContent <> '') and (OutContentType = STATICFILE_CONTENT_TYPE)) then     Context.Content := OutContent;               
  Context.ContentType := OutContentType;   


then can right download file

#15 Re: PDF Engine » Draw bmp Graphic Error When picture with Transparent:=True » 2018-08-25 12:27:27

i Understand:
image is no Transparent  property in pdf,so, should draw image first,then text out words.

#16 PDF Engine » Draw bmp Graphic Error When picture with Transparent:=True » 2018-08-25 10:09:56

gunix
Replies: 2

var
  Fpdf:TPdfDocumentGDI;
  Apic:TGraphic;
begin
  Fpdf:=TPdfDocumentGDI.Create;
  Apic:=TBitmap.Create;
  try
    Fpdf.DefaultPaperSize:=psA4;
    Fpdf.ScreenLogPixels:=Screen.PixelsPerInch;
    Fpdf.AddPage;
    Apic.LoadFromFile('d:\z.bmp');
    Apic.Transparent:=True;
    TBitmap(Apic).TransparentColor:=clWhite;
    Fpdf.VCLCanvas.StretchDraw(Rect(20,20,20+Apic.Width,20+Apic.Height),Apic);
    Fpdf.SaveToFile('d:\test.pdf');
  finally
    Apic.Free;
    Fpdf.Free;
  end;
------------------------------------------------
when pictuere with Transparent property set to be True,can not draw picture in pdf.

Board footer

Powered by FluxBB