📄 blobs.html
字号:
<P>Next step is used to actually bind the content of
a file into input variable:<BR><STRONG>SAString sContent =
SomeFunctionThatReadFileContent("blob.bin");<BR></STRONG>The above line
reads the whole content of a file.<BR><STRONG>cmd.Param("fblob").asBLob() =
sContent;<BR></STRONG>The above line binds parameter
<EM>:fblob</EM> with value of file
content previously
read.</P>
<P>All that we need now is to execute a
query:<BR><STRONG>cmd.Execute();</STRONG>
</P>
<P>For using piecewise capabilities of SQLAPI++ for binding Long or Lob
types see <A href="../Examples/step5.cpp">example</A>.</P>
<A name="Reading Long or Lob data"></A>
<H4>Reading Long or Lob data</H4>
<P>Suppose, we want to retrieve BLob field named
FBLOB from table named TEST where some other field named FKEY
(primary key) is equal to 'KEY' (Select FBLOB from TEST where FKEY =
'KEY'). Field should be read into a file named
'blob.bin'.</P>
<P>As usual, the first thing to do is to create the
objects:<BR><STRONG><FONT face="" size=2><FONT face=System><FONT size=+0>SACommand cmd(&Connection, "Select FBLOB from
TEST where FKEY =
'KEY' ");</FONT></FONT></FONT></STRONG><FONT
size=+0><FONT face=System></FONT></FONT>
<BR>F<A name="Reading Long or Lob data">or more information see
</A><A
href="connect.html">Connecting to databases</A><A
name="Reading Long or Lob data">.</A>
</P>
<P>Next thing to do is to execute a
query:<BR><STRONG>cmd.Execute();</STRONG>
</P>
<P>Next step is used to actually fetch the row and
access BLob data:<BR><STRONG>if(cmd.FetchNext()) // or
while(cmd.FetchNext())<BR>{<BR> SAString sBLob =
cmd.Field("FBLOB").asBLob();<BR>
SomeFunctionToSaveBLobToFile("blob.bin", sBLob);<BR>}</STRONG>
</P>
<P>For using piecewise capabilities of SQLAPI++ for reading Long or
Lob types see <A href="../Examples/step6.cpp">example</A>.</P>
<H3><A name="Server specific notes"></A>Server specific notes</H3>
<P><STRONG>1.</STRONG>
Binding Lob(CLob, BLob) data when working with
<STRONG><A href="../ServerSpecific/Oracle.html" title="Oracle server specific information">Oracle</A></STRONG>
server has some differences from others. It's necessary for
a name of bind variable to be the same
as the column name it associated with. </P>
<P><FONT
face=System>Ex.: Update TEST set <FONT
color=maroon face="">FBLOB = :fblob</FONT>
where FKEY =
'KEY'</FONT>
</P>
<P>
Therefore, it's impossible to bind Lob(CLob,
BLob) data to Oracle database by position. </P>
<P><STRONG>2.</STRONG>
Working with PostgreSQL Large Objects
data (Oid field type) in <A
href="../ServerSpecific/PostgreSQL.html"><STRONG>PostgreSQL</STRONG></A> server has some
particular features. Generally when you fetch Oid field data (which
can point to any object, not necessary PostgreSQL Large Object)
SQLAPI++ returns its value as a number (SQLAPI++ returns an object
identifier). If you want to retrieve Oid field as PostgreSQL Large
Object you should set command-related option
<STRONG>OidTypeInterpretation</STRONG> to
<EM>"LargeObject"</EM> value before the command execution.
See <A
href="../OnLineDoc/Command_setOption.html">SACommand::setOption</A>
for more
detailes. </P>
<P><STRONG>3.</STRONG> The table below shows how SQLAPI++ data types
correspond with servers original data types.</P>
<P>
<TABLE border=1 cellPadding=5 width="100%">
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/Oracle.html" title="Oracle server specific information">Oracle</A></STRONG></P></TD>
<TD>
<P>When using OCI8:<BR><EM>SA_dtLongBinary</EM>
<= > LONG
RAW<BR><EM>SA_dtLongChar</EM> <= >
LONG<BR><EM>SA_dtBLob</EM> <= > BLOB, FILE<BR><EM>SA_dtCLob
</EM><= > CLOB</P>
<P>When using OCI7:<BR><EM>SA_dtLongBinary</EM>
<= > LONG
RAW<BR><EM>SA_dtLongChar</EM> <= >
LONG<BR><EM>SA_dtBLob</EM> = > LONG RAW<BR><EM>SA_dtCLob
</EM>= >
LONG</P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/SQLServer.html" title="SQL Server server specific information">SQL
Server</A>
</STRONG> </P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <= >
IMAGE<BR><EM>SA_dtLongChar</EM> <= >
TEXT<BR><EM>SA_dtBLob</EM> = > IMAGE<BR><EM>SA_dtCLob
</EM>=> TEXT</EM></P></TD></TR>
<TR>
<TD><STRONG><A
href="../ServerSpecific/Sybase.html" title="Sybase server specific information">Sybase</A></STRONG>
<TD>
<P><EM>SA_dtLongBinary</EM> <= >
IMAGE<BR><EM>SA_dtLongChar</EM> <= >
TEXT<BR><EM>SA_dtBLob</EM> = > IMAGE<BR><EM>SA_dtCLob
</EM>=> TEXT</EM></P>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/DB2.html" title="DB2 server specific information">DB2</A></STRONG> </P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <= > LONG
VARGRAPHIC<BR><EM>SA_dtLongChar</EM> <= > LONG
VARCHAR<BR><EM>SA_dtBLob</EM> <= > BLOB<BR><EM>SA_dtCLob
</EM><=>
CLOB, DBCLOB</EM></P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/Informix.html" title="Informix server specific information">Informix</A></STRONG>
</P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <= >
BYTE<BR><EM>SA_dtLongChar</EM> <= >
TEXT<BR><EM>SA_dtBLob</EM> = > BYTE<BR><EM>SA_dtCLob
</EM>=> TEXT</P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/InterBase.html" title="InterBase server specific information">InterBase</A></STRONG></P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> = > BLOB, subtype
0<BR><EM>SA_dtLongChar</EM> = >BLOB, subtype
1<BR><EM>SA_dtBLob</EM>
<=> BLOB, subtype 0<BR><EM>SA_dtCLob
</EM><=> BLOB, subtype 1</EM></P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/SQLBase.html" title="SQLBase server specific information">SQLBase</A></STRONG></P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <= > LONG
VARCHAR<BR><EM>SA_dtLongChar</EM> <= > LONG
VARCHAR<BR><EM>SA_dtBLob</EM> => LONG
VARCHAR<BR><EM>SA_dtCLob </EM>=> LONG VARCHAR</P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/MySQL.html" title="MySQL server specific information">MySQL</A></STRONG></P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <= >
BLOB<BR><EM>SA_dtLongChar</EM> <= >
TEXT<BR><EM>SA_dtBLob</EM> = >
BLOB<BR><EM>SA_dtCLob </EM>= > TEXT</P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/PostgreSQL.html" title="PostgreSQL server specific information">PostgreSQL</A></STRONG></P></TD>
<TD>
<P><EM>SA_dtLongBinary</EM> <=
> BYTEA<BR><EM>SA_dtLongChar</EM> <=
> TEXT<BR><EM>SA_dtBLob</EM> <=
>
Large Object<BR><EM>SA_dtCLob < </EM>= >
Large Object</P></TD></TR>
<TR>
<TD>
<P><STRONG><A
href="../ServerSpecific/ODBC.html" title="ODBC server specific information">ODBC</A></STRONG></P></TD>
<TD>
<P>SQLAPI++ maps data types to ODBC constants.
Actual mapping from constant to SQL type is ODBC driver
specific.</P>
<P><EM>SA_dtLongBinary</EM> <=>
SQL_LONGVARBINARY<BR><EM>SA_dtLongChar</EM> <= >
SQL_LONGVARCHAR<BR><EM>SA_dtBLob</EM> = > SQL_LONGVARBINARY<BR><EM>SA_dtCLob
</EM>=> SQL_LONGVARCHAR</EM></P></TD></TR></TABLE></P>
<P> </P>
<h3>Problems and Questions</h3>
<p>If you don't find the answer to you
questions or have some problems on using the Library, please, send
e-mail to <A href="mailto:howto@sqlapi.com" >howto@sqlapi.com</A>. </p>
<p> </p>
<P> </P>
</td>
<tr></tr>
</table></FONT>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -