Prepared用来确定ADOquery是否要准备好了再查询,如设为true,则系统会先编译后再运行,在多次重复使用某一查询的情况下能有效提升运行速度,但对于只执行一次的查询反面会导致速度下降(编译会消耗时间):
:='select * from table1'
adoquery.prepared:=true;
while condition do
;
end;
ADOQuery.Prepared属性的True/False与; ;方法相对应,
就象;;与的(Ture/False)相对应一样
至于Prepare的功能,是为查询做准备内存区和优化语句;UnPrepare当然是撤消查询所占系统资源了。
//目前查到Insert的这种用法~
:= 'select * from table1';
;
ADOQuery.Insert;
;
('field1').AsString:='field1' ;
;
;
;
:= 'select * from Table';
;
; //添加
('name').Value:= 'test1';
(('logo') as TBlobField).LoadFromFile(Path+'');
//BLOB字段的一种添加方式
; //提交
;
定义:
TUser = packed record
Name : string[50];
CanAsk : boolean;
NumberOfQuestions : integer;
end;
存储:
var
User : TUser;
blobF : TBlobField;
bs : TStream;
begin
:= ;
:= StrToInt() ;
:= ;
;
blobF := ('data') as TBlobField;
bs := (blobF, bmWrite) ;
try
(User,SizeOf(User)) ;
finally
;
end;
end;
读取:
var
User : TUser;
blobF : TBlobField;
bs : TStream;
begin
if ('data').IsBlob then
begin
blobF := ('data') as TBlobField;
bs := (blobF, bmRead) ;
try
(user,sizeof(TUser)) ;
finally
;
end;
end;
:= ;
:= IntToStr() ;
:= ;
end;
//通过sql的存储过程来实现:
//添加
With ADOQuery1 do
begin
Close;
;
(' Insert Into Table1(Field1,Field2)')
(' Values(1,2)');
ExecSQL;
end;
//修改
With ADOQuery1 do
begin
Close;
;
(' Update Table1 Set Field1=11,Field2=22)')
ExecSQL;
end;
//删除
With ADOQuery1 do
begin
Close;
;
(' Delete From Table1')
(' Where Field1=11 and Field2=22');
ExecSQL;
end;
//查询
With ADOQuery1 do
begin
Close;
;
(' Select Field1,Field2 From Table1')
(' Where Field1=11 and Field2=22');
Open;
Close;//用完就释放
end;
//***************************************************
//通过Delphi自有的方法属性实现:
//添加:
with ADOQuery1 do
begin
Close;
;
(' Select * From Table1');
open;
append;
('Field1').Value:= '111';
post;
Close;//用完就释放
end;
//删除:
with ADOQuery1 do
begin
Close;
;
(' Select * From Table1')
(' Where Field1=11 and Field2=22');
open;
delete(选择删除的记录); //默认删除记录指针指向的记录
Close;//用完就释放
end;
//修改:
with ADOQuery1 do
begin
Close;//保险,防止非Close状态~~
;
(' Select * From Table1');
open;
edit;
('Field1').Value:= '111';
post;
Close;//用完就释放
end;