首页 > 其他分享 >调用存储过程进行图片的插入或修改

调用存储过程进行图片的插入或修改

时间:2023-01-27 22:33:19浏览次数:38  
标签:存储 调用 Cmd1 插入 adostream bstr ADODB Conn1 NULL


//pass   blob   to   stored   procedure       //build   by   masterz   20050301   with   VC2003,   Windows   2003,   SQLServer   2000.     #include   "stdafx.h"     #import   "C:/PROGRA~1/COMMON~1/System/ado/msado15.dll"   rename(   "EOF",   "adoEOF"   )     struct   InitOle     {     InitOle()     {   ::CoInitialize(NULL);   }     ~InitOle()   {   ::CoUninitialize();     }     }   _init_InitOle_;     void   PrintProviderError(ADODB::_ConnectionPtr   pConnection);         void   print_properties(LPCTSTR   name,   ADODB::PropertiesPtr   Properties)     {     long   prop_count   =   Properties->GetCount();     printf("%s   property   count   =   %d/n",name,prop_count);     for(long   i=0;i<prop_count;i++)     {     printf("%s   property   [%d]:%s/n",name,i,(LPCSTR)Properties->GetItem(i)->Name);     }     }     int   main(int   argc,   char*   argv[])     {     ADODB::_ConnectionPtr     Conn1;     ADODB::_CommandPtr         Cmd1;     ADODB::_ParameterPtr     oldParam=   NULL;     ADODB::_ParameterPtr   inParam=NULL;     ADODB::_ParameterPtr   blobParam=NULL;     _variant_t     vtEmpty   (DISP_E_PARAMNOTFOUND,   VT_ERROR);     _variant_t     vtEmpty2   (DISP_E_PARAMNOTFOUND,   VT_ERROR);     //_bstr_t         bstrConnect="Provider=OraOLEDB.Oracle;Data   Source=orcl;User   Id=system;Password=oracle;";       _bstr_t         bstrConnect="Driver={SQL   Server};Server=localhost;Database=zxg;Uid=sa;Pwd=sa;"   ;       //create   procedure   dbo.insert_update_blob(@fn   varchar(9),@filecontent   image)   as     //   if   exists   (select   *   from   table1   where   filename=@fn   )     //   begin     //   update   table1   set   content=@filecontent   where   filename=@fn     //   end     //   else     //   begin     //   insert   table1   (filename,content)   values(@fn,@filecontent)     //   end     _bstr_t         bstrSP("{CALL   insert_update_blob(?,?)}"   );     try     {     _variant_t   varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);       ADODB::_StreamPtr   adostream;     adostream.CreateInstance(_T("ADODB.Stream"));     adostream->Type   =   ADODB::adTypeBinary;     adostream->Open(varOptional,ADODB::adModeUnknown,   ADODB::adOpenStreamUnspecified,   _T(""),   _T(""));       adostream->LoadFromFile("C://masterz//20041229.rar");     _variant_t   vReadTo   =   adostream->Read(ADODB::adReadAll);       long   blob_size   =   adostream->GetSize();     adostream->Close();         _bstr_t   bstrEmpty;     Conn1.CreateInstance(   __uuidof(   ADODB::Connection   )   );     Cmd1.CreateInstance(   __uuidof(   ADODB::Command   )   );     Conn1->ConnectionString   =   bstrConnect;     Conn1->Open(   bstrConnect,   bstrEmpty,   bstrEmpty,   -1   );     Cmd1->ActiveConnection   =   Conn1;     Cmd1->CommandText             =   bstrSP;     Cmd1->CommandType             =   ADODB::adCmdText;     Conn1->Properties->Refresh();     inParam   =   Cmd1->CreateParameter(_bstr_t("@fn"),ADODB::adChar,ADODB::adParamInput,2,_variant_t(   "a"   ));     Cmd1->Parameters->Append(inParam);     blobParam   =   Cmd1->CreateParameter(_bstr_t("@filecontent"),ADODB::adLongVarBinary,ADODB::adParamInput,blob_size,vReadTo);     Cmd1->Parameters->Append(blobParam);     Cmd1->Properties->Refresh();     print_properties("Cmd1",Cmd1->Properties);     Cmd1->Execute(NULL,NULL,ADODB::adExecuteNoRecords);     Conn1->Close();     //select   filename,datalength(content)   from   table1   where   datalength(content)>0     }     catch(_com_error   &e)     {     _bstr_t   bstrSource(e.Source());     _bstr_t   bstrDescription(e.Description());     printf("/nCOM   error   occurred,   Source   :   %s   /n   Description   :   %s   /n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);     PrintProviderError(Conn1);     }     printf("/nprogram   end/n");     return   0;     }     VOID   PrintProviderError(ADODB::_ConnectionPtr   pConnection)     {     ADODB::ErrorPtr     pErr   =   NULL;     long             nCount   =   0;     long             i   =   0;     if(   (pConnection->Errors->Count)   >   0)     {     nCount   =   pConnection->Errors->Count;     for(i   =   0;   i   <   nCount;   i++)     {     pErr   =   pConnection->Errors->GetItem(i);     printf("/n/t   Error   number:   %x/t%s",   pErr->Number,   (LPCSTR)pErr->Description);     }     }     }

标签:存储,调用,Cmd1,插入,adostream,bstr,ADODB,Conn1,NULL
From: https://blog.51cto.com/u_15942605/6024354

相关文章

  • iframe子窗口调用父窗口方法
    //一个iframe页面调用另一个iframe页面的方法self.parent.frames["sort_bottom"].mapp($("#id").val(),$("#actor").val(),txt);更多内容及Java+大数据个人原创视频,可关注......
  • 本地存储(localStorage)如何设置过期时间?
    思考在我们使用​​cookie​​​的时候是可以设置有效期的,但是​​localStorage​​​本身是没有该机制的,只能人为的手动删除,否则会一直存放在浏览器当中,可不可以跟cookie一......
  • Vue3 封装扩展并简化Vuex在组件中的调用
    如果你在项目中使用了vuex模块化,并且在项目中使用actions中函数调用频率高,推荐了解一下这种方式。比如下面两种方式调用,第一个是直接传参设置,第二个是添加了异步ajax......
  • PostgreSQL(四)存储结构
    先上一张图:这是 PostgreSQL的 DMS管理方式,与oracle管理一样。DMS(databasemanagementspace)数据库管理空间,数据库中管理,容器是预分配的文件。SMS(systemmanagementsp......
  • 一个调用ATL Server WebServices 的AJAX客户端
    请将下面的代码完整复制到soapclient.js中/**//*****************************************************************************AJAXJavascript"SOAPClient"libra......
  • 利用python函数调用ffmpeg批量进行转码
    本人学习python没几天,代码也没记住,写个函数到处查笔记,东拼西凑的。累……但是最终还是搞定了。欢迎高手指导,谢谢!单个文件转码#学会如何在python调用bat文件importos,......
  • CGAL中Eigen库的调用
    CGAL中的部分功能会使用到iEigen库如果在使用这些功能时,没有引用Eigen库,就会出现如下问题: 这时的解决方案为:1.官网上下载相应支持的Eigen版本http://eigen.tuxfamily......
  • 插入单片机,电脑没反应,安装CH340也没用,之前误删了几个驱动,现在回不去了
    提问:遇到问题:插入单片机,USB接口没反应,之前在其他设备那误删了一下东西(泪奔)试着解决:安装了ch340,安装成功了,但是设备管理器没有显示,串口也有感叹号解答:可能的原因是设......
  • 编写代码实现:求一个整数存储在内存中的二进制中1的个数
    目的:统计num的补码中有几个1法一#include<stdio.h>intmain(){intnum=0;intcount=0;scanf("%d",&num);//3--011//二进制:模2除2while(num)//因为二进制只有0和1,......
  • mysql存储过程和游标
    创建存储过程存储过程和定义函数相似,使用CREATEPROCEDURE 存储名(),BEGIN 和END之间为“函数体”。CREATETABLEBlog(authorVARCHAR(25),blogTEXT,......