⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myldbconverts.pas

📁 一个本地database引擎,支持中文T_Sql查询,兼容DELPHI标准数据库控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
               begin
                if (IsPatternEscaped and (PatternPtr^ = EscapeChar)) then
                  inc(PatternPtr);
                tmp1[0] := StrPtr^;
                tmp2[0] := PatternPtr^;
                if (bIgnoreCase) then
                 //bEQ := (Q_AnsiCompTextL(tmp1, tmp2, 1) = 0)
                 bEQ := (CompareString(LOCALE_USER_DEFAULT,
                         NORM_IGNORECASE + SORT_STRINGSORT,
                         tmp1, 1, tmp2, 1) - 2) = 0
                else
                 //bEQ := (Q_AnsiCompStrL(tmp1, tmp2, 1) = 0);
                 bEQ := (CompareString(LOCALE_USER_DEFAULT,
                         SORT_STRINGSORT,
                         tmp1, 1, tmp2, 1) - 2) = 0;
                if (bEQ) then
                 begin
                  inc(StrPtr);
                  inc(PatternPtr);
                 end
                else
                 begin
                  Result:=False;
                  exit;
                 end;
               end;
           end; // case
         end; // non-simple cases
  until false;
end;// IsStrMatchPattern

//------------------------------------------------------------------------------
// Like '%_' compare for WideString
//------------------------------------------------------------------------------
function IsWideStrMatchPattern(StrPtr: PWideChar; PatternPtr: PWideChar; IsPatternEscaped: Boolean; EscapeChar: WideChar; bIgnoreCase:boolean): Boolean;
var i: integer;
    bOk: boolean;
begin
  repeat
      if (CompareStringW(LOCALE_USER_DEFAULT,
                        NORM_IGNORECASE + SORT_STRINGSORT,
                        PatternPtr,
                        Length(PatternPtr),
                        WideChar(WildCardMultipleChar),
                        1)-2 = 0) then
       begin
         Result:=True;
         exit;
       end
      else if (StrPtr^=#0) and (PatternPtr^ <> #0) then
       begin
         Result:=False;
         exit;
       end
      else if (StrPtr^=#0) then
       begin
         Result:=True;
         exit;
       end
      else
         begin
           case PatternPtr^ of
            WildCardMultipleChar:
               begin
                for i:=0 to Length(StrPtr)-1 do
                 begin
                  if IsWideStrMatchPattern(StrPtr+i,PatternPtr+1,IsPatternEscaped,EscapeChar,bIgnoreCase) then
                   begin
                    Result := True;
                    exit;
                   end;
                 end;
                Result := False;
                exit;
               end;
            WildCardSingleChar:
               begin
                inc(StrPtr);
                inc(PatternPtr);
               end;
            else
               begin
                bOk := false;
                if (IsPatternEscaped and (PatternPtr^ = EscapeChar)) then
                  inc(PatternPtr);
                if bIgnoreCase then
                 begin
                  if (MYLDBStrUtils.CompareStringW(LOCALE_USER_DEFAULT,
                        NORM_IGNORECASE + SORT_STRINGSORT,
                        PatternPtr, 1, StrPtr,1)-2 = 0) then
                   bOk := true;
                 end
                else
                 begin
                  if (MYLDBStrUtils.CompareStringW(LOCALE_USER_DEFAULT,
                        SORT_STRINGSORT,
                        PatternPtr, 1, StrPtr,1)-2 = 0) then
                   bOk := true;
                 end;

                if (bOk) then
                 begin
                  inc(StrPtr);
                  inc(PatternPtr);
                 end
                else
                 begin
                  Result:=False;
                  exit;
                 end;
               end;
           end; // case
         end; // non-simple cases
  until false;
end;// IsWideStrMatchPattern


// DestField.Value := SrcField.Value
procedure AssignField(SrcField, DestField: TField);
var
  A: Variant;
  SrcBlobStream: TStream;
  DestBlobStream: TStream;
  Size: Longint;
  Header: TGraphicHeader;
  ws: WideString;
begin
  case SrcField.DataType of
    ftLargeint:
      if TLargeintField(SrcField).IsNull = True then
        TLargeintField(DestField).Clear
      else
        TLargeintField(DestField).AsLargeInt := TLargeintField(SrcField).AsLargeInt;
    ftVarBytes:
      begin
        // 5.13 - fix ALTER TABLE problem
        if DestField.Value <> SrcField.Value then
        begin
          A := SrcField.Value;
          {$IFDEF D5H}
          DestField.SetData(@A, False);
          {$ELSE}
          DestField.SetData(@A);
          {$ENDIF}
        end;
      end;
    else
      begin
        if (SrcField.IsBlob and DestField.IsBlob) then
          begin
            SrcBlobStream := SrcField.DataSet.CreateBlobStream(SrcField, bmRead);
            DestBlobStream := DestField.Dataset.CreateBlobStream(DestField, bmWrite);
            try
              Size := SrcBlobStream.Size;
              // check for Graphic Header
              if Size >= SizeOf(TGraphicHeader) then
              begin
                SrcBlobStream.Read(Header, SizeOf(Header));
                if (Header.Count <> 1) or (Header.HType <> $0100) or
                  (Header.Size <> Size - SizeOf(Header)) then
                  SrcBlobStream.Position := 0;
              end;
              DestBlobStream.CopyFrom(SrcBlobStream, SrcBlobStream.Size-SrcBlobStream.Position);
            finally
              SrcBlobStream.Free;
              DestBlobStream.Free;
            end;
          end
        else
          if ((SrcField.DataType = ftWideString) and DestField.IsBlob) then
            begin
              DestBlobStream := DestField.Dataset.CreateBlobStream(DestField, bmWrite);
              try
                ws := SrcField.Value;
                DestBlobStream.Write(PWideChar(ws)^, Length(ws)*sizeof(WideChar));
              finally
                DestBlobStream.Free;
              end;
            end
          else
            if ((DestField.DataType = ftWideString) and SrcField.IsBlob) then
              begin
                SrcBlobStream := SrcField.DataSet.CreateBlobStream(SrcField, bmRead);
                try
                  SetLength(ws, SrcBlobStream.Size div sizeof(WideChar));
                  SrcBlobStream.Read(PWideChar(ws)^, SrcBlobStream.Size);
                  DestField.Value := ws;
                finally
                  SrcBlobStream.Free;
                end;
              end
            else begin
              if (DestField is TLargeintField) and (not (SrcField is TLargeIntField)) then
                TLargeIntField(DestField).Value := SrcField.AsInteger
              else
                DestField.Assign(SrcField);
            end;
      end;
  end;
end;

function ExtractNumericPart(const DateTimeStr: String; DigitsCount: Integer; var Value: Word; var Pos: Integer): Boolean;
var
  s: String;
  count: Integer;
begin
  s := '';
  count := 0;
  while ((pos <= Length(DateTimeStr)) and not (DateTimeStr[pos] in ['-',' ',':'])) do
    begin
      if (DateTimeStr[pos] < '0') or (DateTimeStr[pos] > '9') then
        break;
      s := s + DateTimeStr[pos];
      Inc(pos);
      Inc(Count);
    end;
  Inc(pos);
  Result := (Count = DigitsCount);
  if Result then
    Value := StrToInt(s);
end;

// 'YYYY-MM-DD' => TDate
function ISODateStrToDate(const DateStr: String; var Date: TDateTime): Boolean;
var
  Year, Month, Day: Word;
  pos: Integer;
begin
{
<date value> ::=
    <years value> <minus sign> <months value>
        <minus sign> <days value>
}
  pos := 1;
  Result := ExtractNumericPart(DateStr,4,Year,Pos);
  if (Result) then
    Result := ExtractNumericPart(DateStr,2,Month,Pos);
  if (Result) then
    Result := ExtractNumericPart(DateStr,2,Day, Pos);
  if (Result) then
    Result := (Pos > Length(DateStr));
  if (Result) then
    Date := EncodeDate(Year,Month,Day);
end;


// 'HH:MM:SS' => TTime
function ISOTimeStrToTime(const TimeStr: String; var Time: TDateTime): Boolean;
var
  Hour,Min,Sec,MSec: Word;
  pos: Integer;
begin
  Pos := 1;
  MSec := 0;
  Result := ExtractNumericPart(TimeStr,2,Hour,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStr,2,Min,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStr,2,Sec,Pos);
  if (Result) then
    Result := (Pos > Length(TimeStr));
  if (Result) then
    Time := EncodeTime(Hour,Min,Sec,MSec);
end;


// 'YYYY-MM-DD HH:MM:SS' => TDateTime
function ISOTimeStampStrToDateTime(const TimeStampStr: String; var DateTime: TDateTime): Boolean;
var
  Year, Month, Day: Word;
  Hour,Min,Sec,MSec: Word;
  pos: Integer;
begin
  Pos := 1;
  MSec := 0;
  Result := ExtractNumericPart(TimeStampStr,4,Year,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStampStr,2,Month,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStampStr,2,Day,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStampStr,2,Hour,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStampStr,2,Min,Pos);
  if (Result) then
    Result := ExtractNumericPart(TimeStampStr,2,Sec,Pos);
  if (Result) then
    Result := (Pos > Length(TimeStampStr));
  if (Result) then
    DateTime := EncodeDateTime(Year,Month,Day, Hour,Min,Sec,MSec);
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -