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

📄 umysqlhelpers.pas

📁 用delphi连接mysql的组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  if aValue then
    result:=aFlag or CLIENT_LONG_PASSWORD
  else
    result:=aFlag and not CLIENT_LONG_PASSWORD;
end;

//takes aflags as imputs and sets/resets into the result : found rows
function SetFOUNDROWS(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_FOUND_ROWS
  else
    result:=aFlag and not CLIENT_FOUND_ROWS;
end;

//takes aflags as imputs and sets/resets into the result : long flag
function SetLONGFLAG(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_LONG_FLAG
  else
    result:=aFlag and not CLIENT_LONG_FLAG;
end;

//takes aflags as imputs and sets/resets into the result : connect with db
function SetCONNECTWITHDB(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_CONNECT_WITH_DB
  else
    result:=aFlag and not CLIENT_CONNECT_WITH_DB;
end;

//takes aflags as imputs and sets/resets into the result : no schema
function SetNOSCHEMA(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_NO_SCHEMA
  else
    result:=aFlag and not CLIENT_NO_SCHEMA;
end;

//takes aflags as imputs and sets/resets into the result : compress
function SetCOMPRESS(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_COMPRESS
  else
    result:=aFlag and not CLIENT_COMPRESS;
end;

//takes aflags as imputs and sets/resets into the result : ODBC
function SetODBC(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_ODBC
  else
    result:=aFlag and not CLIENT_ODBC;
end;

//takes aflags as imputs and sets/resets into the result : local files
function SetLOCALFILES(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_LOCAL_FILES
  else
    result:=aFlag and not CLIENT_LOCAL_FILES;
end;

//takes aflags as imputs and sets/resets into the result : ignore spaces
function SetIGNORESPACE(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_IGNORE_SPACE
  else
    result:=aFlag and not CLIENT_IGNORE_SPACE;
end;

//takes aflags as imputs and sets/resets into the result : change user
function SetCHANGEUSER(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_CHANGE_USER
  else
    result:=aFlag and not CLIENT_CHANGE_USER;
end;

//takes aflags as imputs and sets/resets into the result : interactive
function SetINTERACTIVE(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_INTERACTIVE
  else
    result:=aFlag and not CLIENT_INTERACTIVE;
end;

//takes aflags as imputs and sets/resets into the result : ssl
function SetSSL(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_SSL
  else
    result:=aFlag and not CLIENT_SSL;
end;

//takes aflags as imputs and sets/resets into the result : ignore sigpipe
function SetIGNORESIGPIPE(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_IGNORE_SIGPIPE
  else
    result:=aFlag and not CLIENT_IGNORE_SIGPIPE;
end;

//takes aflags as imputs and sets/resets into the result : transactions
function SetTRANSACTIONS(aFlag:longint; aValue:boolean):longint;
begin
  if aValue then
    result:=aFlag or CLIENT_TRANSACTIONS
  else
    result:=aFlag and not CLIENT_TRANSACTIONS;
end;

////////////////////////////////////////////////////////////////////////////////
//different type of flags check for fields

//returns true if not null
function IsNOTNULL(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and NOT_NULL_FLAG = NOT_NULL_FLAG;
end;

//returns true if primary key
function IsPRIKEY(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and PRI_KEY_FLAG = PRI_KEY_FLAG;
end;

//returns true if unique key
function IsUNIQUEKEY(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and UNIQUE_KEY_FLAG = UNIQUE_KEY_FLAG;
end;

//returns true if multiple key
function IsMULTIPLEKEY(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and MULTIPLE_KEY_FLAG = MULTIPLE_KEY_FLAG;
end;

//returns true if blob
function IsBLOB(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and BLOB_FLAG = BLOB_FLAG;
end;

//returns true if unsigned
function IsUNSIGNED(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and UNSIGNED_FLAG = UNSIGNED_FLAG;
end;

//returns true if zero fill
function IsZEROFILL(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and ZEROFILL_FLAG = ZEROFILL_FLAG;
end;

//returns true if binary
function IsBINARY(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and BINARY_FLAG = BINARY_FLAG;
end;

//returns true if enum
function IsENUM(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and ENUM_FLAG = ENUM_FLAG;
end;

//returns true if autoincrement
function IsAUTOINCREMENT(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and AUTO_INCREMENT_FLAG = AUTO_INCREMENT_FLAG;
end;

//returns true if timestamp
function IsTIMESTAMP(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and TIMESTAMP_FLAG = TIMESTAMP_FLAG;
end;

//returns true if set
function IsSET(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and SET_FLAG = SET_FLAG;
end;

//returns true if numeric
function IsNUM(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and NUM_FLAG = NUM_FLAG;
end;

//returns true if part of a key
function IsPARTKEY(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and PART_KEY_FLAG = PART_KEY_FLAG;
end;

//returns true if group
function IsGROUP(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and GROUP_FLAG = GROUP_FLAG;
end;

//returns true unique
function IsUNIQUE(aFieldDef:PMysql_FieldDef):boolean;
begin
  result:=false;
  if assigned(aFieldDef) then
    result:=aFieldDef.Flags and UNIQUE_FLAG = UNIQUE_FLAG;
end;


////////////////////////////////////////////////////////////////////////////////
// convert a string to escape string format as in c syntax
// when sending a query with blobs a blob should be escaped and enclosed between '' or ""
function EscapeStr(aString: string): string;
var
  I, j, k: Integer;
  pc: PChar;
begin
  j := 0;
  k := Length(aString);
  //how many chars needs escape mark?
  for I := 1 to k do
    if aString[I] in ['''','"','\',#9,#10,#13,#0] then
      Inc(j);
  SetLength(Result, k + j); //dimension the result to right size
  pc := PChar(Result); //a pchar for walking the result
  for I := 1 to k do
    begin
      if aString[I] in ['''','"','\',#9,#10,#13,#0] then
        begin //if this char needs escape
          pc^ := '\'; //escape
          Inc(pc);//next char
          case aString[I] of
            #9:  pc^ := 't';
            #10: pc^ := 'n';
            #13: pc^ := 'r';
            #0:  pc^ := '0';
          else
            pc^ := aString[I];
          end;
        end
      else
        pc^ := aString[I];
      Inc(pc);//next char
    end;
end;

end.

⌨️ 快捷键说明

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