SQL Server与 InterBase 数据转换

2022-06-29 00:00:00 专区 订阅 付费 控件 导出到

目标:把SQL SERVER数据库中的数据表导出到InterBae数据库;反过来亦然!

要求:表结构一致,对应的字段类型一致。

主要控件:FIREDAC 与 FIREDAC ETL/delphi 10.3

界面如下:




导出到 InterBase 运行结果:




view as text::

object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 491
ClientWidth = 784
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 0
Top = 303
Width = 784
Height = 188
ActivePage = TabSheet1
Align = alBottom
TabOrder = 0
object TabSheet1: TTabSheet
Caption = ' SQL SERVER('#28304') '
object DBGrid1: TDBGrid
Left = 0
Top = 25
Width = 776
Height = 248
Align = alTop
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
Columns = <
item
Expanded = False
FieldName = 'SRDATE'
Width = 80
Visible = True
end
item
Expanded = False
FieldName = 'SRID'
Width = 80
Visible = True
end
item
Expanded = False
FieldName = 'SRNAME'
Width = 180
Visible = True
end
item
Expanded = False
FieldName = 'DESCRIPTION'
Width = 360
Visible = True
end>
end
object DBNavigator1: TDBNavigator
Left = 0
Top = 0
Width = 776
Height = 25
DataSource = DataSource1
Align = alTop
TabOrder = 1
end
end
object TabSheet2: TTabSheet
Caption = ' INTERBASE XE('#30446#26631') '
ImageIndex = 1
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 867
ExplicitHeight = 373
object DBGrid2: TDBGrid
Left = 0
Top = 25
Width = 776
Height = 248
Align = alTop
DataSource = DataSource2
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object DBNavigator2: TDBNavigator
Left = 0
Top = 0
Width = 776
Height = 25
DataSource = DataSource2
Align = alTop
TabOrder = 1
ExplicitTop = 8
ExplicitWidth = 867
end
end
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 784
Height = 81
Align = alTop
Caption = 'Panel1'
ShowCaption = False
TabOrder = 1
object ToInterBasebTN: TButton
Left = 1
Top = 1
Width = 382
Height = 79
Align = alClient
Caption = #23548#20986#21040' InterBase'
TabOrder = 0
OnClick = ToInterBasebTNClick
end
object delbTN: TButton
Left = 383
Top = 1
Width = 400
Height = 79
Align = alRight
Caption = #21024#38500
TabOrder = 1
end
end
object DataSource1: TDataSource
DataSet = FDQuery1
Left = 48
Top = 240
end
object DataSource2: TDataSource
DataSet = FDQuery2
Left = 608
Top = 240
end
object FDConnection1: TFDConnection
Params.Strings = (
'Database=FIREDACDEMODB'
'User_Name=sa'
'Password=123'
'Server=win7server'
'DriverID=MSSQL')
Connected = True
LoginPrompt = False
Left = 48
Top = 128
end
object FDQuery1: TFDQuery
Active = True
Connection = FDConnection1
SQL.Strings = (
'select * from SEMINARS')
Left = 48
Top = 185
end
object FDConnection2: TFDConnection
Params.Strings = (

'Database=127.0.0.1:F:\delphi101firedac Demo\Data\FIREDACDEMODB.G' +
'DB'
'User_Name=sysdba'
'Password=masterkey'
'CharacterSet=UTF8'
'DriverID=IB')
Connected = True
LoginPrompt = False
Left = 608
Top = 128
end
object FDQuery2: TFDQuery
Active = True
Connection = FDConnection2
SQL.Strings = (
'select * from SEMINARS')
Left = 608
Top = 185
end
object FDQuery3: TFDQuery
Connection = FDConnection1
SQL.Strings = (
'delete from SEMINARS')
Left = 744
Top = 160
end
object FDGUIxWaitCursor1: TFDGUIxWaitCursor
Provider = 'Forms'
Left = 368
Top = 258
end
object FDBatchMoveDataSetReader1: TFDBatchMoveDataSetReader
DataSet = FDQuery1
Left = 368
Top = 218
end
object FDBatchMoveDataSetWriter1: TFDBatchMoveDataSetWriter
DataSet = FDQuery2
Optimise = False
Left = 368
Top = 170
end
object FDBatchMove1: TFDBatchMove
Reader = FDBatchMoveDataSetReader1
Writer = FDBatchMoveDataSetWriter1
Mappings = <>
LogFileName = 'Data.log'
Left = 368
Top = 114
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.DB, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
FireDAC.Phys.MSSQL, FireDAC.Phys.MSSQLDef, FireDAC.Stan.Param, FireDAC.DatS,
FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Phys.IB, FireDAC.Phys.IBDef,
FireDAC.VCLUI.Wait, FireDAC.Comp.BatchMove, FireDAC.Comp.BatchMove.DataSet,
FireDAC.Comp.UI, FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.ExtCtrls,
Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls, Vcl.ComCtrls;

type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
DBGrid2: TDBGrid;
DBNavigator2: TDBNavigator;
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
FDConnection2: TFDConnection;
FDQuery2: TFDQuery;
FDQuery3: TFDQuery;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
FDBatchMoveDataSetReader1: TFDBatchMoveDataSetReader;
FDBatchMoveDataSetWriter1: TFDBatchMoveDataSetWriter;
FDBatchMove1: TFDBatchMove;
Panel1: TPanel;
ToInterBasebTN: TButton;
delbTN: TButton;
procedure ToInterBasebTNClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ToInterBasebTNClick(Sender: TObject);
begin //导出到InterBase
FDBatchMove1.Execute;
//FDBatchMove1.GuessFormat;
PageControl1.ActivePageIndex := 1;
end;

end.

注意事项:

InterBase连接控件一定要设置成 'CharacterSet=UTF8',否则 转换时会弹出





————————————————
版权声明:本文为CSDN博主「qq_457565758」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_25439957/article/details/86593907

相关文章