TIceSQLCustomTable
组件包内的 Ice.ORM.pas 单元 中有一个 TIceSQLCustomTable 类
我们继承自这个类 即可在数据库中创建表且对此表进行增删改操作。
type [IceSQLTable('test_table_icy',diSqlServer)] //表名 和数据库 这里指向了 sqlserver 顺便 说下只支持 mysql sqlite sqlserver 哈哈 TTestTable = class(TIceSQLCustomTable) public [IceSQLField('id','type:int;pk:true;ai:true')] // 此处声明一个 字段为 id的 主键 = pk , 自增长 = ai property ID: string index 0 read GetValue write SetValue; [IceSQLField('key_test','type:varchar(50);nn:true;')] //此处声明一个字段为 key_test 的 类型为 varchar(50) 不是空值的 property Key: string index 1 read GetValue write SetValue; [IceSQLField('value_test','type:varchar(50);def:'''';')] //此处声明一个字段为 value_test 的 类型为 varchar(50) 默认为空的 property value: string index 2 read GetValue write SetValue; [IceSQLField('age','type:int;def:0;')] //此处声明一个字段为 age 的 类型为 int的默认为0 property Age: string index 3 read GetValue write SetValue; end;
上面的代码声明一个表类 如没用特别需要 这样定义即可使用 ,注: index 顺序切勿写错 嘿。。。
TTestValue = record//对应表内的字段 id: Integer; value_test: string; end;
声明一个结构体 等下用于数据获取
procedure IceFearlessly_test.ORM2; var data: TTestValue; List: TIceArrayRecord<TTestValue>; begin with TTestTable.Create(SqlServerDB('SQL_SERVER_CON')) do (* Ice.ORM.pas 有对应数据库的方法 链接名 我是通过 TIceDBManager 组件添加 也可以是 TIceOrm.SQL 方法返回 *) try Key:= 'meow1'; Value:= '喵喵喵喵喵2'; Age:= 'hj1'; Update('id = ?',1);// 更新记录 CreateTable;//创建表 如果不存在才会创建 Key:= 'icy'; Value:= '这是一个测试咯'; Self.WriteLn('记录ID: ' + Insert.ToString); //插入一条记录 Key:= 'meow'; Value:= '喵喵喵喵喵'; Age:= '21'; Self.WriteLn('记录ID: ' + Insert.ToString);// 同上 Data:= Take<TTestValue>('id = ?',3);//取一条记录 Self.WriteLn(data.id.ToString); Self.WriteLn(data.value_test); List:= Rows<TTestValue>('id > 0');//取多条 if list.Count > 0 then begin for var P: TTestValue in List do begin Self.WriteLn(p.id.ToString); Self.WriteLn(p.value_test); SELF.WriteLn(''); end; List.Clear; end; Self.WriteLn(Scan<string>('key_test', 'id = 1'));//取一个字段 finally Free; end; end;
好啦 上面就是对一个表进行操作。如果为按照 通过下面地址 下载安装包.
还没有评论,来说两句吧...