分享

ClientDataSet的隐含功能-3

 远在南非 2010-07-09
begin
  try
  Result := CreateOleObject(\’ADODB.Connection\’);
  Result.CursorLocation := adUseServer;
  Result.IsolationLevel := adXactCursorStability;
  Result.Mode := adModeReadWrite;
  Result.Provider := \’SQLOLEDB.1\’;
  except
  if not VarIsEmpty(Result) then Result := Unassigned;
  end;
  end;
  procedure FreeConnection(var cnn: OleVariant);
  begin
  if not VarIsEmpty(cnn) then
  begin
  if cnn.State <> adStateClosed then cnn.Close;
  cnn := Unassigned;
  end;
  end;
  function CreateRecordset: OleVariant;
  begin
  try
  Result := CreateOleObject(\’ADODB.Recordset\’);
  Result.CacheSize := 1000;
  Result.CursorType := adOpenStatic;
  Result.CursorLocation := adUseServer;
  Result.LockType := adLockOptimistic;
  except
  if not VarIsEmpty(Result) then Result := Unassigned;
  end;
  end;
  procedure FreeRecordset(var rst: OleVariant);
  begin
  FreeConnection(rst);
  end;
  function CreateCommand: OleVariant;
  begin
  try
  Result := CreateOleObject(\’ADODB.Command\’);
  Result.CommandType := adCmdText;
  Result.CommandTimeout := 5;
  except
  if not VarIsEmpty(Result) then Result := Unassigned;
  end;
  end;
  procedure FreeCommand(var cmd: OleVariant);
  begin
  if not VarIsEmpty(cmd) then cmd := Unassigned;
  end;
  function ConnectToDB(cnn: OleVariant; const db, host, usr, pwd: string): Boolean;
  begin
  Result := not VarIsEmpty(cnn);
  if Result then
  begin
  if cnn.State <> adStateClosed then cnn.Close;
  cnn.ConnectionString :=
  \’Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=\’ +
  db + \’;Data Source=\’ + host + \’;Connect Timeout=5;\’ +
  \’Use Procedure for Prepare=1\’;
  try
  cnn.Open(cnn.ConnectionString, usr, pwd, -1);
  except
  Result := False;
  end;
  end;
  end;
  function ExecSQL(cnn, rst: OleVariant; const sql: string): Boolean;
  begin
  Result := not (VarIsEmpty(cnn) or VarIsEmpty(rst)) and (cnn.State = adStateOpen);
  if Result then
  begin
  if rst.State <> adStateClosed then rst.Close;
  try
  rst.Open(sql, cnn, adOpenStatic, adLockOptimistic, adCmdText);
  except
  Result := False;
  end;
  end;
  end;
  function ExecSQLA(cnn, cmd: OleVariant; const sql: string): Boolean;
  begin
  Result := not (VarIsEmpty(cnn) or VarIsEmpty(cmd)) and (cnn.State = adStateOpen);
  if Result then来源

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多