Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
How to insert BLOB into MySQL using ODBC driver 3.51

How to insert BLOB into MySQL using ODBC driver 3.51

2006-06-10       - By Tim Lucia

 Back
Reply:     1     2  

Here is a VB (ADO Record Sets) function I am currently using to insert blobs
in both MySQL and Oracle.  It's not quite what you're looking for, but I
offer it in case it gives you some idea(s).

Tim


Private Function StoreBlobInDB(ByVal sDataSourceName As String, _
                              ByVal sBlobTable As String, _
                              ByVal sBlobColumn As String, _
                              ByVal sFilePath As String) As Integer
                         
   Dim conn As ADODB.Connection 'adodb connection variable
   Dim rs As ADODB.Recordset
   Set conn = New ADODB.Connection
   Set rs = New ADODB.Recordset

   Dim mystream As ADODB.Stream
   Set mystream = New ADODB.Stream
   mystream.Type = adTypeBinary
   mystream.Open
   mystream.LoadFromFile sFilePath
   
   ' See http://dev.mysql.com/doc/refman/5.0/en/connection-parameters.html
   ' for a description of the connection option values
   ' We require 1 + 2 + 8 + 32 + 2048 + 16384, which are set
   ' in the data source.
   
   conn.ConnectionString = sDataSourceName
   conn.CursorLocation = adUseClient
   conn.Open
   
   If conn.Properties("DBMS Name") = "MySQL" Then
       rs.Open "SELECT * FROM " & sBlobTable & " WHERE 1=0", conn,
adOpenDynamic, adLockPessimistic
       With rs
           .AddNew
           .fields(sBlobColumn) = mystream.Read
           .Update
       End With
       rs.Close
       rs.Open "SELECT LAST_INSERT_ID() AS ID"
       Dim blobId As Integer
       blobId = rs(0)
   Else
       If conn.Properties("DBMS Name") = "Orac" Then
           Dim seq As String
           seq = sBlobTable & "_SEQ.NEXTVAL"
           rs.Open "SELECT " & seq & " AS ID FROM DUAL", conn,
adOpenDynamic, adLockPessimistic
           blobId = rs(0)
           rs.Close
           rs.Open "SELECT * FROM " & sBlobTable & " WHERE 1=0", conn,
adOpenDynamic, adLockPessimistic
           With rs
               .AddNew
               .fields(sBlobColumn) = mystream.Read
               .fields("ID") = blobId
               .Update
           End With
       Else
           Err.Raise ERROR_DSN_NOT_SUPPORTED, "StoreBlobInDB", _
           "Configuration error: DSN " & sDataSourceName & " is
unsupported.  Type = " & _
           conn.Properties("DBMS Name")
       End If
   End If


   rs.Close
   Set rs = Nothing
   conn.Close
   Set conn = Nothing
   
   StoreBlobInDB = blobId

End Function

-- --Original Message-- --
From: RAMANAIAH NAGINENI [mailto:nagramana@(protected)]
Sent: Saturday, June 10, 2006 12:57 AM
To: myodbc@(protected)
Subject: How to insert BLOB into MySQL using ODBC driver 3.51

I am facing problem in  inserting BLOB into MySQL using ODBC driver 3.51. I
am working in C# dot net and my application is Windows application.
I await your suggestions in this regard to solve the problem.
Ramana

__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
Cox & Kings presents 'Win a trip for 2 to Austria' Contest. Click here
http://www.coxandkings.com/cms/products/specialpromotions/?link=view&CM_ID=7
8


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/myodbc?unsub=timlucia@(protected)


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/myodbc?unsub=mysql@(protected)