怎样将Variant类型的数据存入BLOB字段又如何从数据库的BLOB字段读取数据存入Variant类型的变量中

Songzhiq 2004-10-10 12:46:14
如何将Variant类型的数据存入BLOB字段又如何从数据库的BLOB字段读取数据存入Variant类型的变量中?

能提供一些源码吗?十分感谢!!
...全文
122 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
robbyzi 2004-12-14
  • 打赏
  • 举报
回复
我这有一篇收集的文章你可以看看:
我想把一些文件存进数据库中,这些文件的类型也不统一,有图片,有文档,也有其他格式的,请问数据库的表中,存取这些文件的字段应该选取什么数据类型呀?是sql_variant吗?另外应该怎么在程序中用代码存取呢

下面是一个使用TQuery往content表(主键file_id)中插入一条记录的例子,
script为一个BLOB字段:
TBlobStream *pScriptStream;
//插入一条记录
strSQL1="insert into content(file_id,script,key_image) values('";
strSQL1=strSQL1+m_szFileID+"',null,null)";
dmStoryEditor->qryExec->SQL->Clear();
dmStoryEditor->qryExec->SQL->Add(strSQL1);
dmStoryEditor->qryExec->ExecSQL();
dmStoryEditor->qryExec->Close();
//整理要写入的Blob数据
LockMemories(NewsScript);
NewsScript.GetEdition(NewsScript.m_ScriptHead.byteEditionNum);
NewsScript.m_pScript=(BYTE *)GlobalLock(NewsScript.m_hScript);
if(NewsScript.m_pScript!=NULL)
{
//再将刚插入的记录读出来,使该Query与该条记录关联
strSQL1="select file_id,script from content where file_id='"+
m_szFileID+"'";
//允许该Query写
dmStoryEditor->qryExec->RequestLive=true;
dmStoryEditor->qryExec->SQL->Clear();
dmStoryEditor->qryExec->SQL->Add(strSQL1);
dmStoryEditor->qryExec->Open();
dmStoryEditor->qryExec->First();
//将该Query置为可写
dmStoryEditor->qryExec->Edit();
pScriptStream=new TBlobStream((TBlobField*)dmStoryEditor->
qryExec->FieldByName("script"),bmReadWrite);
pScriptStream->Write(NewsScript.m_pScript,
NewsScript.m_lScriptRealSize);
dmStoryEditor->qryExec->Post();
dmStoryEditor->qryExec->RequestLive=false;
delete pScriptStream;
}
GlobalUnlock(NewsScript.m_hScript);
UnLockMemories(NewsScript);


sqlserver用image数据类型就可以地
lihongxing2002 2004-12-14
  • 打赏
  • 举报
回复
up,把你的代码贴出来啊
Songzhiq 2004-10-10
  • 打赏
  • 举报
回复
我的Variant变量中保存的是二进制流,我不知道如何存入数据库中,又如何从数据库的BLOB类型的字段中
读取数据至Variant变量中。

有高手知道吗?急!!
COKING 2004-10-10
  • 打赏
  • 举报
回复
帖出你存的代码!
FastReport问题集 Q: 我怎样添加我的自定义函数? A: 使用 TfrReport.OnUserFunction 事件. 这里有一个简单的例子: procedure TForm1.frReport1UserFunction(const Name: String; p1, p2, p3: Variant; var val: Variant); begin if AnsiCompareText(‘SUMTOSTR‘, Name) = 0 then val := My_Convertion_Routine(frParser.Calc(p1)); end; 然后,你就可以在报表(任何表达式或脚本)的任何地方使用 SumToStr 函数了。 Q: 但是它仅仅能工作在一个TfrReport组件。可我想在任何地方(在所有的TfrReport组件)使用的我的自定义函数? A: 使 OnUserFunction event 句柄作为所有组件的公用句柄。如果你不能做到这一点,你需要创建函数库: type TMyFunctionLibrary = class(TfrFunctionLibrary) public constructor Create; override; procedure DoFunction(Fno: Integer; p1, p2, p3: Variant; var val: Variant); override; end; constructor TMyFunctionLibrary.Create; begin inherited Create; with List do begin Add(‘DATETOSTR‘); Add(‘SUMTOSTR‘); end; end; procedure TMyFunctionLibrary.DoFunction(Fno: Integer; p1, p2, p3: Variant; var val: Variant); begin val := 0; case Fno of 0: val := My_DateConvertion_Routine(frParser.Calc(p1)); 1: val := My_SumConvertion_Routine(frParser.Calc(p1)); end; end; 要注册函数库,调用 frRegisterFunctionLibrary(TMyFunctionLibrary); 要卸载函数库,调用 frUnRegisterFunctionLibrary(TMyFunctionLibrary); Q: 我怎样将我的函数添加到函数列表 (用表达式生成器)? A: 使用 frAddFunctionDesc 过程 (在FR_Class 单元): frAddFunctionDesc(FuncLib, ‘SUMTOSTR‘, ‘My functions‘, ‘SUMTOSTR()/Converts number to its verbal presentation.‘); 注意: "/" 符号是必须的! 它从它的描述分隔函数语法。 FuncLib 被声明为你自己的函数库 (如果你不使用函数库可以将其设置为nil). 当函数库未注册时,所有它的函数将自动从函数列表删除。 ---------------- 使用变量 ------------------------------------- Q: 我怎样编程实现填充变量列表(在数据词典)? A: 数据词典的所有变量及分类都被存储在 TfrReport.Dictionary.Variables . with frReport1.Dictionary do begin // 创建分类(名称用空白) Variables[‘ New category‘] := ‘‘; // 创建变量 Variables[‘New Variable‘] := ‘CustomerData.Customers."CustNo"‘; Variables[‘Another Variable‘] := ‘Page#‘; end; Q: 我定义了字符串变量: with frReport1.Dictionary do Variables[‘Month‘] := ‘March‘; 但是当我运行报表是,出现了错误,为什么? A: 因为 FastReport 假定数据词典的字符串变量值是一个表达式,它需要分析、计算它。 可以使用其它的方法: with frReport1.Dictionary do Variables[‘Month‘] := ‘‘‘‘ + ‘March‘ + ‘‘‘‘; 或者, 使用 frVariables 来传输固定数据到报表。 Q: 我不想在数据词典显示某些数据集? A: 使用 TfrReport.Dictionary.DisabledDatasets: with frReport1.Dictionary do begin // 关闭该数据集 DisabledDatasets.Add(‘CustomerData.Bio‘); // 或者, 关闭整个数据模块/窗体 DisabledDatasets.Add(‘CustomerData*‘); end; Q: 我怎样将数据传送到报表? A: 有几个方法可以实现它. 第一是使用全局对象 frVariables (在 FR_Class 单元被定义): frVariables[‘My variable‘] := 10; 这段代码创建了一个名称为“My variable”,值为 10 的变量。这是最好的传输固定数据的报表的方法。 第二种方法是使用 TfrReport.OnGetValue 事件. 这可以使用这个方法来传送动态数据、记录等。 procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant); begin if ParName = ‘MyField‘ then ParValue := Table1MyField.Value; end; 最后, 第三种方法是通过编程在数据词典定义变量(可以参考以前的问题): with frReport1.Dictionary do begin Variables[‘MyVariable‘] := ‘CustomerData.Customers."CustNo"‘; Variables[‘Another Variable‘] := ‘10‘; end; Q: 我能在报表和程序间传送数据吗? A: 使用 frVariables 对象. 如果你在报表的任何对象的脚本写入以下代码: MyVariable := 10 那么,在你的程序,你可以使用以下代码来获取 MyVariable 的值: v := frVariables[‘MyVariable‘]; ---------------- 脚本 (FastReport Pascal) --------------------------------- Q: Band 是否可以使用脚本? A: 当然. 选择 band ,然后按 Ctrl+Enter 或在对象浏览器选择 "OnBeforePrint" 属性。 Q: 报表页是否可以使用脚本? A: 当然. 选择页 (在空白处单击) ,然后在对象浏览器选择 "OnBeforePrint" 属性。如果该页是一个对话框窗体,那么这个属性就是 "OnActivate". Q: 我有两个对象: Memo1 和 Memo2. 我能否在 Memo1 的脚本调用 Memo2 的属性和方法? A: 当然, 例如,你可以这样做: 对象名.属性名. Q: 在脚本,我可以使用对象的哪些属性? A: 几乎所有你能在对象浏览器看到的属性。例如,可以使用 Font.Name, Font.Size等来存取字体属性。 ---------------- 其它问题 -------------------------------------------- Q: 怎样改变多页报表某一页的顺序? A: 拖动页标签到目的位置。 Q: 我想查看所有的字段变量,我想在报表使用列表来实现它? A: 设置 TfrReport.MixVariablesAndDBFields := True.现在,所有的数据字段变量可在“插入数据字段”对话框可存取了。 Q: 我不想显示导入选项对话框? A: 在导入组件(比如,TfrTextExport)设置所有必需的选项,然后通过设置ShowDialog属性为False来关闭此对话框。 Q: 为什么 TotalPages 变量不起作用? 它总是返回 0. A: 在你的报表设置 Two-pass 选项. 要设置它,你需要在报表设计器的“文件”菜单,打开“报表选项”对话框。 Q: 我用BLOB字段来存储我的报表。当我运行报表设计器时,它显示我的报表未命名? A: 在运行报表设计器前,这样做: frReport1.FileName := ‘Name of my report‘; Q: 我想在重新定义报表设计器的“打开”及“保存”按钮的功能? A: 查看 TfrDesigner 组件. 它有几个必需的事件: OnLoadReport 和 OnSaveReport. 这里有一小段代码例子: procedure TForm1.frDesigner1LoadReport(Report: TfrReport; var ReportName: String; var Opened: Boolean); begin with MyOpenDialog do begin Opened := ShowModal = mrOk; if Opened then begin Report.LoadFromBlobField(…); ReportName := …; end; end; end; procedure TForm1.frDesigner1SaveReport(Report: TfrReport; var ReportName: String; SaveAs: Boolean; var Saved: Boolean); begin if SaveAs then with MySaveDialog do begin Saved := ShowModal = mrOk; if Saved then begin Report.SaveToBlobField(…); ReportName := …; end; end else Report.SaveToBlobField(…); end; Q: 在 QR , 我可以写这样的代码: QRLabel1.Caption := ‘Some text‘. 我可以用FR这样做吗? A: FR 对象并不是一个组件 (这并不像 QR, RB). 但使用 TfrReport.FindObject 方法可以通过对象名称找到该对象。 var t: TfrMemoView; begin t := TfrMemoView(frReport1.FindObject(‘Memo1‘)); if t <> nil then t.Memo.Text := ‘FastReport‘; end; Q: 我想在用户预览(TfrPreview组件)自定义热键? A: 这个组件有个窗口: Tform 属性. 将自定义句柄指定到 Window.OnKeyDown 属性. Q: Fast Report 2.4 不能装载 FreeReport 2.21 文件? A: 这仅需要使用16进制数改变报表文件的第一字节,然后在源代码修改下面的部分。在这些修改之后, 装载报表并保存它. 最后,返回到源代码处. FR_Class: function ReadString(Stream: Tstream): String; begin { if frVersion >= 23 then} Result := frReadString(Stream) {else Result := frReadString22(Stream);} end; procedure ReadMemo(Stream: Tstream; Memo: Tstrings); begin { if frVersion >= 23 then} frReadMemo(Stream, Memo){ else frReadMemo22(Stream, Memo);} end; FR_Utils: procedure frReadMemo(Stream: Tstream; l: Tstrings); var s: String; b: Byte; n: Word; begin l.Clear; l.Text := frReadString(Stream); exit; Stream.Read(n, 2); if n > 0 then repeat Stream.Read(n, 2); SetLength(s, n); Stream.Read(s[1], n); l.Add(s); Stream.Read(b, 1); until b = 0 else Stream.Read(b, 1); end; function frReadString(Stream: Tstream): String; var s: String; n: Integer; b: Byte; begin Stream.Read(n, 4); SetLength(s, n); Stream.Read(s[1], n); if (n > 0) and (s[n] = #$0A) then SetLength(s, n - 2); // Stream.Read(b, 1); Result := s; end; Q: 怎样不在打印预览打印报表? A: 这里有一段代码: frReport1.PrepareReport; frReport1.PrintPreparedReport(‘‘, 1, True, frAll); 或 frReport1.PrintPreparedReportDlg; Q: 我想在报表旋转图片。问题是这张图片是由我的应用程序生成的。是否有方法可以在打印前将这幅图片装载到报表? A: 使用 TfrReport.OnBeforePrint 事件: if View.Name = ‘Picture1‘ then TfrPictureView(View).Picture.LoadFromFile(…) 或 .Assign 或 .你所想要做的任何事情
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver
org.eclipse.swt.SWT.class org.eclipse.swt.SWTError.class org.eclipse.swt.SWTException.class org.eclipse.swt.accessibility.ACC.class org.eclipse.swt.accessibility.Accessible.class org.eclipse.swt.accessibility.AccessibleActionAdapter.class org.eclipse.swt.accessibility.AccessibleActionEvent.class org.eclipse.swt.accessibility.AccessibleActionListener.class org.eclipse.swt.accessibility.AccessibleAdapter.class org.eclipse.swt.accessibility.AccessibleAttributeAdapter.class org.eclipse.swt.accessibility.AccessibleAttributeEvent.class org.eclipse.swt.accessibility.AccessibleAttributeListener.class org.eclipse.swt.accessibility.AccessibleControlAdapter.class org.eclipse.swt.accessibility.AccessibleControlEvent.class org.eclipse.swt.accessibility.AccessibleControlListener.class org.eclipse.swt.accessibility.AccessibleEditableTextAdapter.class org.eclipse.swt.accessibility.AccessibleEditableTextEvent.class org.eclipse.swt.accessibility.AccessibleEditableTextListener.class org.eclipse.swt.accessibility.AccessibleEvent.class org.eclipse.swt.accessibility.AccessibleHyperlinkAdapter.class org.eclipse.swt.accessibility.AccessibleHyperlinkEvent.class org.eclipse.swt.accessibility.AccessibleHyperlinkListener.class org.eclipse.swt.accessibility.AccessibleListener.class org.eclipse.swt.accessibility.AccessibleTableAdapter.class org.eclipse.swt.accessibility.AccessibleTableCellAdapter.class org.eclipse.swt.accessibility.AccessibleTableCellEvent.class org.eclipse.swt.accessibility.AccessibleTableCellListener.class org.eclipse.swt.accessibility.AccessibleTableEvent.class org.eclipse.swt.accessibility.AccessibleTableListener.class org.eclipse.swt.accessibility.AccessibleTextAdapter.class org.eclipse.swt.accessibility.AccessibleTextAttributeEvent.class org.eclipse.swt.accessibility.AccessibleTextEvent.class org.eclipse.swt.accessibility.AccessibleTextExtendedAdapter.class org.eclipse.swt.accessibility.AccessibleTextExtendedListener.class org.eclipse.swt.accessibility.AccessibleTextListen

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧