简体   繁体   English

TDataSet Descendant

[英]TDataSet Descendant

I have a very good DirectMySQL unit, which is ready to be used and i want it to be a TDataset descendant so i can use it with QuickReport, i just want MySQL Query with DirectMySQL which descendant from TDataset. 我有一个很好的DirectMySQL单元,可以随时使用,我希望它成为TDataset的后代,以便可以与QuickReport一起使用,我只希望MySQL Query与DirectData一起从TDataset继承。

Everything was ok until i tried to access a big table with 10.000 rows and more. 一切正常,直到我尝试访问具有10.000行及更多行的大表。 It was unstable, the error was unpredictable and not always shown but it likely happened after you played with other tables. 这是不稳定的,错误是不可预测的,并不总是显示,但它可能发生在你玩其他表后。

It happened in GetFieldData(Field: TField; Buffer: Pointer): boolean; 它发生在GetFieldData(Field:TField; Buffer:Pointer)中:boolean; which used to get the field value from MySQL rows. 用于从MySQL行获取字段值。

Here's the code, 这是代码,

function TMySQLQuery.GetFieldData(Field: TField; Buffer: Pointer): Boolean;
var
  I, CT: Integer;
  Row: TMySQL_Row;
  TBuf: PChar;
  FD: PMySQL_FieldDef;
begin
  UpdateCursorPos; ------------> This code is after i got the error but no result
  Resync([]);      ------------> This code is after i got the error but no result
  Result := false;

  Row := oRecordset.CurrentRow;
  I := Field.FieldNo-1;
  FD := oRecordset.FieldDef(I);
  if Not Assigned(FD) then
    FD := oRecordset.FieldDef(I);
  TBuf := PP(Row)[i];

  Try
    CT := MySQLWriteFieldData(fd.field_type, fd.length, fd.decimals, TBuf, PChar(Buffer));
    Result := Buffer <> nil;

  Finally
    Row := nil; ------------> This code is after i got the error but no result
    FD := nil; ------------> This code is after i got the error but no result
    TBuf := nil; ------------> This code is after i got the error but no result
    Buffer := nil; ------------> This code is after i got the error but no result
  End;
end;

{
These codes below are to translate the data type 
from MySQL Data type to a TDataset data type 
and move mysql row (TBuf) to TDataset buffer to display. 
And error always comes up from this function 
when moving mysql row to buffer.
}
function TMySQLQuery.MySQLWriteFieldData(AType: byte;
  ASize: Integer; ADec: cardinal; Source, Dest: PChar): Integer;
var
  VI: Integer;
  VF: Double;
  VD: TDateTime;  
begin
     Result := MySQLDataSize(AType, ASize, ADec);

     case AType of
       FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
       FIELD_TYPE_INT24:
         begin
              if Source <> '' then
                 VI := StrToInt(Source)
              else
                  VI := 0;
              Move(VI, Dest^, Result);
         end;
       FIELD_TYPE_DECIMAL, FIELD_TYPE_NEWDECIMAL:
         begin
              if source <> '' then
                VF := internalStrToCurr(Source)
              else
                VF := 0;
              Move(VF, Dest^, Result);
         end;
       FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
         begin
              if Source <> '' then
                 VF := InternalStrToFloat(Source)
              else
                  VF := 0;
              Move(VF, Dest^, Result);
         end;
       FIELD_TYPE_TIMESTAMP:
         begin
              if Source <> '' then
                 VD := InternalStrToTimeStamp(Source)
              else
                  VD := 0;
              Move(VD, Dest^, Result);
         end;
       FIELD_TYPE_DATETIME:
         begin
              if Source <> '' then
                 VD := InternalStrToDateTime(Source)
              else
                  VD := 0;
              Move(VD, Dest^, Result);
         end;
       FIELD_TYPE_DATE:
         begin
              if Source <> '' then
                 VD := InternalStrToDate(Source)
              else
                  VD := 0;
              Move(VD, Dest^, Result);
         end;
       FIELD_TYPE_TIME:
         begin
              if Source <> '' then
                 VD := InternalStrToTime(Source)
              else
                  VD := 0;
              Move(VD, Dest^, Result);
         end;
       FIELD_TYPE_STRING, FIELD_TYPE_VAR_STRING,
       FIELD_TYPE_ENUM, FIELD_TYPE_SET:
         begin
              if Source = nil then
                 Dest^ := #0
              else
                Move(Source^, Dest^, Result);
         end;

        Else
          Result := 0;
          Raise EMySQLError.Create( 'Write field data  -  Unknown type field' );
     end;
end;

My guess for now is it's memory related problem. 我现在的猜测是它与内存有关的问题。

I am stacked. 我堆积了。 Anyone could help? 有人可以帮忙吗? I also need TDataset documentation which list availlable descendant function and how to use it, or how to descendant from TDataset. 我还需要TDataset文档,其中列出了可用的后代函数以及如何使用它,或者如何从TDataset继承。 anyone have them? 谁有他们? I am lack of this kind of doumentation. 我缺乏这种doumentation。

  1. GetFieldData cannot have UpdateCursorPos and Resync calls. GetFieldData不能具有UpdateCursorPos和Resync调用。 Otherwise you may get unpredicatable errors. 否则,您可能会遇到无法预料的错误。
  2. FD := oRecordset.FieldDef(I) ... FD := oRecordset.FieldDef(I); FD:= oRecordset.FieldDef(I)... FD:= oRecordset.FieldDef(I); - looks strange. - 看起来很奇怪。 Second assigment is not needed. 不需要第二次分配。
  3. finally ... end with local variables reset is not needed. 最后......不需要重置局部变量。
  4. I have no idea what returns MySQLDataSize. 我不知道什么返回MySQLDataSize。 For example, MySQLDataSize may return size in Delphi data type representation units, or may return length of data returned by MySQL. 例如,MySQLDataSize可以返回Delphi数据类型表示单元中的大小,或者可以返回MySQL返回的数据长度。 But depending on that MySQLWriteFieldData may be correct or may be not. 但是,取决于那个MySQLWriteFieldData可能是正确的,也可能不是正确的。
  5. I dont know how DirectMySQL works. 我不知道DirectMySQL是如何工作的。 If it uses raw TCP/IP to talk to MySQL, then the problem may be there. 如果它使用原始TCP / IP与MySQL通信,则可能存在问题。 For example, it incorrectly handles a sequence of packets. 例如,它错误地处理了一系列数据包。
  6. And finally - what are the errors you are getting ? 最后 - 你得到的错误是什么? What is your Delphi version ? 你的Delphi版本是什么? What is your MySQL client and server versions ? 你的MySQL客户端和服务器版本是什么?
  7. And so on .... 等等 ....

IOW, that will be really hard to say, what is wrong. IOW,这真的很难说,出了什么问题。 To do so, I for example, will need to get all sources, sit at Delphi IDE debugger and analyze many details of what is going on - sorry, no time :) 为此,我需要获取所有资源,坐在Delphi IDE调试器中并分析许多正在发生的细节 - 抱歉,没时间:)

现在通过在行尾添加#0解决了...非常感谢所有回答我问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM