DataSnap与FireDAC三层
相交资料:
http://blog.csdn.net/shuaihj/article/details/6129131
http://www.cnblogs.com/hnxxcxg/p/4007876.html
http://www.cnblogs.com/hnxxcxg/p/4008789.html
http://www.dfwlt.com/forum.php?mod=viewthread&tid=729 (生成Unit2)
PS:
右键点击TSQLConnection选择“Generate DataSnap client classes”生成,Uuit2。
服务端实例:
unit ServerMethodsUnit1; interface uses System.SysUtils, System.Classes, System.Json,
Datasnap.DSServer, Datasnap.DSAuth, DataSnap.DSProviderDataModuleAdapter,
Datasnap.Provider, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteDef,
FireDAC.UI.Intf, FireDAC.VCLUI.Wait, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool,
FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Stan.Param, FireDAC.DatS,
FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, FireDAC.Comp.UI, FireDAC.Phys.SQLite,
FireDAC.Stan.Storage,//未知
FireDAC.Stan.StorageBin,//未知
FireDAC.Stan.StorageJSON,//未知
FireDAC.Stan.StorageXML,//未知
Data.FireDACJSONReflect;//TFDJSONDataSets返回表使用 type
TServerMethods1 = class(TDSServerModule)
DataSetProvider1: TDataSetProvider; //要增加的控件
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;//要增加的控件
FDGUIxWaitCursor1: TFDGUIxWaitCursor; //要增加的控件
FDConnection1: TFDConnection; //要增加的控件
FDQuery1: TFDQuery;//要增加的控件
DataSource1: TDataSource;//要增加的控件
private
{ Private declarations }
public
{ Public declarations }
function EchoString(Value: string): string;
function ReverseString(Value: string): string;
//用户查询数据
function GetDataTable(Value: string): TFDJSONDataSets;
//用户删除记录
function DeleteData(Value:string):string; end; implementation {$R *.dfm} uses System.StrUtils; function TServerMethods1.EchoString(Value: string): string;
begin
Result := Value;
end; function TServerMethods1.ReverseString(Value: string): string;
begin
Result := System.StrUtils.ReverseString(Value);
end; //用户查询数据
function TServerMethods1.GetDataTable(Value: string): TFDJSONDataSets;
begin
//指定数据库
FDConnection1.DriverName := 'SQLite';
FDConnection1.Params.Add('Database=E:\diarydate.db');
//控件的联接情况
FDQuery1.Connection := FDConnection1;
DataSource1.DataSet := FDQuery1;
//用户查询
FDQuery1.SQL.Text := Value;//SELECT * FROM tproject
//打开数据集
FDConnection1.Open();
FDQuery1.Open();
//建立多个数据集返回集
Result := TFDJSONDataSets.Create;
//你也可以给自己的数据集起外名字
//TFDJSONDataSetsWriter.ListAdd(Result, 'A123', FDQuery1);
TFDJSONDataSetsWriter.ListAdd(Result, FDQuery1);
end; //用户删除记录
function TServerMethods1.DeleteData(Value: string): string;
begin
//代表空
Result := '';
//指定数据库
FDConnection1.DriverName := 'SQLite';
FDConnection1.Params.Add('Database=E:\diarydate.db');
//控件的联接情况
FDQuery1.Connection := FDConnection1;
DataSource1.DataSet := FDQuery1;
//用户查询
FDQuery1.SQL.Text := Value;//delete from tproject where fid=2
//打开数据集
FDConnection1.Open();
FDQuery1.ExecSQL;
//代表完成
Result := '';
end; end.
客户端实例:
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DBXDataSnap, IPPeerClient,
Data.DBXCommon, Data.DB, Data.SqlExpr, Data.FMTBcd, Vcl.StdCtrls,
FireDAC.Stan.Intf, FireDAC.Comp.DataMove,
FireDAC.Stan.Option, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf,
FireDAC.DApt,
FireDAC.Comp.Client,
FireDAC.Stan.Param, FireDAC.Stan.Error,
FireDAC.Comp.DataSet, Vcl.Grids, Vcl.DBGrids, Datasnap.DBClient,
Datasnap.DSConnect,
Unit2,//DataSnap单元
Data.FireDACJSONReflect,//TFDJSONDataSets使用
FireDAC.Stan.StorageJSON,//未知
FireDAC.Stan.StorageBin, //未知
FireDAC.Stan.StorageXML,//未知
FireDAC.Stan.Storage, //未知
Datasnap.Provider; type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection; //要增加的控件
SqlServerMethod1: TSqlServerMethod; //要增加的控件
button1: TButton; //要增加的控件
button2: TButton; //要增加的控件
FDStanStorageJSONLink1: TFDStanStorageJSONLink; //要增加的控件
FDStanStorageBinLink1: TFDStanStorageBinLink; //要增加的控件 FDMemTable1: TFDMemTable; //要增加的控件
DBGrid1: TDBGrid; //要增加的控件
DataSource1: TDataSource; //要增加的控件
Button3: TButton; //要增加的控件
procedure button1Click(Sender: TObject);
procedure button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.button1Click(Sender: TObject);
begin
SqlServerMethod1.ParamByName('Value').AsString:='Hello world';
SqlServerMethod1.ExecuteMethod;
ShowMessage(SqlServerMethod1.ParamByName('ReturnParameter').AsString);
end; procedure TForm1.button2Click(Sender: TObject);
var
oDSList: TFDJSONDataSets;
oDataModel: TServerMethods1Client;
begin
try
//连接指定IP和Port的应用服务器
SQLConnection1.Close;
//这我用的是本机的,所以就没有写
//SQLConnection1.Params.Values['HostName'] := edtIP.Text;
//SQLConnection1.Params.Values['Port'] := edtPort.Text;
try
SQLConnection1.Open;
try
//创建应用服务器上的Sample Methods在客户端的实现类
oDataModel := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
//执行服务器上的方法
FDMemTable1.Close;
oDSList := oDataModel.GetDataTable('SELECT * FROM tproject');
FDMemTable1.AppendData(TFDJSONDataSetsReader.GetListValue(oDSList, ));
FDMemTable1.Open;
finally
oDataModel.Free;
end;
except
on E: Exception do
ShowMessage(E.Message);
end;
finally
SQLConnection1.Close;
end;
end; procedure TForm1.Button3Click(Sender: TObject);
var
oDataModel: TServerMethods1Client;
bIsTrue: string;
begin
try
//连接指定IP和Port的应用服务器
SQLConnection1.Close;
//这我用的是本机的,所以就没有写
//SQLConnection1.Params.Values['HostName'] := edtIP.Text;
//SQLConnection1.Params.Values['Port'] := edtPort.Text;
try
SQLConnection1.Open;
try
//创建应用服务器上的Sample Methods在客户端的实现类
oDataModel := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
bIsTrue := oDataModel.DeleteData('delete from tproject where fid=2');
ShowMessage(bIsTrue);
finally
oDataModel.Free;
end;
except
on E: Exception do
ShowMessage(E.Message);
end;
finally
SQLConnection1.Close;
end;
end; end.
DataSnap与FireDAC三层的更多相关文章
- 论DATASNAP结合FIREDAC的使用方法
论DATASNAP结合FIREDAC的使用方法 自DELPHI XE5开始引入FIREDAC数据引擎以来,FIREDAC就正式成为了官方的数据引擎.一直到XE10.1 UPDATE1,据笔者观察,FI ...
- Delphi 使用 Datasnap 的几种三层应用技术总结
Delphi 使用 Datasnap 进行三层应用开发,积累了几种技术,总结如下: 1.(推荐!)在 Datasnap 服务端 使用 TDatasetProvider,客户端 使用 TDSProv ...
- DataSnap 多层返回数据集分析FireDAC JSON
采用服务器返回数据,一种是返回字符串数据例如JSON,跨平台跨语言,任何语言调用都支持兼容,类似WEBService. 第二种是紧密结合c++builder语言,传输DataSet,可以是Client ...
- FireDAC 接占线导致另一个 hstmt DataSnap
[FireDAC][Phys][ODBC][Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt 同样的程序,在2台win10 正常,1台win10 报连 ...
- 基于Delphi的三层数据库系统的实现方法
基于Delphi的三层数据库系统的实现方法 1 引言 当前的数据库应用系统中,按其结构划分为两类,一类是两层结构的数据库应系统,另一类是多层结构的数据库应用系统. 两层结构的数据库应用系统包括客 ...
- 客户端如何连接 DataSnap Server 调用服务的方法
一般http访问的地址是 http://localhost:8099/datasnap/rest/TServerMethods1/EchoString/abc 一.用FDConnection1连接Da ...
- Android开发数据库三层应用-DataSnap
Android开发数据库三层应用-DataSnap http://www.2ccc.com/news/Html/?1517.html 核心提示:我觉得Delphi最强大的的功能之一就是开发数据库三层应 ...
- DATASNAP为支持FIREDAC而增加的远程方法的数据类型TFDJSONDataSets
前面的博客提到用FIREDAC全面替代COM那一套东西:DATAPROVIDER,OLEVARIANT,CLIENTDATASET,DBEXPRESS... 显然,DATASNAP的远程方法必须增加对 ...
- 一个例子说明如何在DataSnap中使用FireDAC
一.FireDAC调用DataSnap远程方法查询数据示例 1.服务端使用FDQUERY查询数据并返回TDATASET: function TServerMethods1.GetData(var sq ...
随机推荐
- Android Studio上的几个插件
转载:http://blog.csdn.net/maosidiaoxian/article/details/44992655 以下所有插件都可以在Idea的插件库中找到,如果你与我一样在Android ...
- [Codeforces677B]Vanya and Food Processor(模拟,数学)
题目链接:http://codeforces.com/contest/677/problem/B 题意:n个土豆,每个土豆高ai.现在有个加工机,最高能放h,每次能加工k.问需要多少次才能把土豆全加工 ...
- android的ScaleGestureDetector缩放类详解
文章由多出组合,它们来自: http://elvajxw.iteye.com/blog/1308452 http://www.cnblogs.com/lknlfy/archive/2012/03/11 ...
- IT玄幻小说
职业 设计:菜鸟 美工<初级,中级,高级,资深> 设计师<初级,中级,高级,资深> 大神 前端:菜鸟 前端<初级,中级,高级,资深> 架构师<初级,中 ...
- Java Web编程的主要组件技术——Struts入门
参考书籍:<J2EE开源编程精要15讲> Struts是一个开源的Java Web框架,很好地实现了MVC设计模式.通过一个配置文件,把各个层面的应用组件联系起来,使组件在程序层面联系较少 ...
- mac里vmware fusion桥接设置
1 桥接模式网络连接:选择以太网 2 在虚拟机操作系统里设置好ip,手动设置,将虚拟机当成一台存在的物理机设置 3 在宿主MAC偏好设置-网络-以太网-高级-硬件, 配置:自动改为 手工, 速度:选择 ...
- LeetCode Linked List Cycle 单链表环
题意:给一个单链表,判断其是否出现环! 思路:搞两个指针,每次,一个走两步,另一个走一步.若有环,他们会相遇,若无环,走两步的指针必定会先遇到NULL. /** * Definition for si ...
- LeetCode Number of Islands 岛的数量(DFS,BFS)
题意:0代表水,1代表陆地,那么被水围起来的就是岛了,给一个01矩阵,问有多少个岛? 思路:DFS还是比较短,实现了一下.如果一个点已经被遍历过了,那就将其置为0就行了,不要去搜0的. class S ...
- Java [leetcode 4] Median of Two Sorted Arrays
问题描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of t ...
- unsigned 和 signed
http://www.cnblogs.com/stonehat/archive/2011/10/14/2212141.html http://m.blog.csdn.net/blog/u0100862 ...