473,857 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python Oracle 10g odbc blob insertion problem

Dear all,

I cannot find a solution for my problem with inserting a blob object
(>4000 in length) into an ORACLE database via ODBC.
I have tried the two ways of inserting the blob object (a zip file):
1)
fp = open("c:/test/test.zip", "r+b")
data = fp.read()
s = odbc.odbc(cs)
qry = s.cursor()
qry.execute("In sert into tBlob (data) values ('%s')" %
data.encode('he x'))
return the error: Input String Too Long Limit: 4096
2)
qry.execute("In sert into tBlob (data) values (?)",
data.encode('he x'))
does not return error, but it does not insert the record correctly.
Any help will be fully appreciated...

Mar 22 '07 #1
8 3864
Godzilla wrote:
Dear all,

I cannot find a solution for my problem with inserting a blob object
(>4000 in length) into an ORACLE database via ODBC.
I have tried the two ways of inserting the blob object (a zip file):
1)
fp = open("c:/test/test.zip", "r+b")
data = fp.read()
s = odbc.odbc(cs)
qry = s.cursor()
qry.execute("In sert into tBlob (data) values ('%s')" %
data.encode('he x'))
return the error: Input String Too Long Limit: 4096
2)
qry.execute("In sert into tBlob (data) values (?)",
data.encode('he x'))
does not return error, but it does not insert the record correctly.
Any help will be fully appreciated...
Try, just on the off chance:

qry.execute("In sert into tBlob (data) values (?)",
(data.encode('h ex'), ))
The second argument to execute should always be a tuple. And be aware
that the odbc module hasn't had much maintenance lately.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #2
On 22 Mar, 10:21, "Godzilla" <godzillais...@ gmail.comwrote:
>
I cannot find a solution for my problem with inserting a blob object
(>4000 in length) into an ORACLE database via ODBC.
This brings back "happy" memories with Oracle 9i and JDBC.
I have tried the two ways of inserting the blob object (a zip file):

1)
fp = open("c:/test/test.zip", "r+b")
data = fp.read()
s = odbc.odbc(cs)
qry = s.cursor()
qry.execute("In sert into tBlob (data) values ('%s')" %
data.encode('he x'))

return the error: Input String Too Long Limit: 4096

2)
qry.execute("In sert into tBlob (data) values (?)",
data.encode('he x'))

does not return error, but it does not insert the record correctly.

Any help will be fully appreciated...
If I recall correctly, JDBC provided an API to stream the contents
into the column. That is, you needed to provide an instance of one of
the mutually incompatible Java stream classes (I don't remember which
one) when setting the value, and then the database would suck up the
contents. It's quite possible that a similar mechanism involving file-
like objects exists in the different Python modules for Oracle,
although I haven't checked.

Paul

Mar 22 '07 #3
Godzilla wrote:
Dear all,

I cannot find a solution for my problem with inserting a blob object
(>4000 in length) into an ORACLE database via ODBC.
I have tried the two ways of inserting the blob object (a zip file):
1)
fp = open("c:/test/test.zip", "r+b")
data = fp.read()
s = odbc.odbc(cs)
qry = s.cursor()
qry.execute("In sert into tBlob (data) values ('%s')" %
data.encode('he x'))
return the error: Input String Too Long Limit: 4096
2)
qry.execute("In sert into tBlob (data) values (?)",
data.encode('he x'))
does not return error, but it does not insert the record correctly.
Any help will be fully appreciated...
I would certainly recommend that you think about using the cxOracle
package rather than relying on odbc. Most Orcale users do, with evident
satisfaction.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #4
On Mar 22, 10:56 pm, Steve Holden <s...@holdenweb .comwrote:
Godzilla wrote:
Dear all,
I cannot find a solution for my problem with inserting a blob object
(>4000 in length) into an ORACLE database via ODBC.
I have tried the two ways of inserting the blob object (a zip file):
1)
fp = open("c:/test/test.zip", "r+b")
data = fp.read()
s = odbc.odbc(cs)
qry = s.cursor()
qry.execute("In sert into tBlob (data) values ('%s')" %
data.encode('he x'))
return the error: Input String Too Long Limit: 4096
2)
qry.execute("In sert into tBlob (data) values (?)",
data.encode('he x'))
does not return error, but it does not insert the record correctly.
Any help will be fully appreciated...

I would certainly recommend that you think about using the cxOracle
package rather than relying on odbc. Most Orcale users do, with evident
satisfaction.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com- Hide quoted text -

- Show quoted text -
Thanks guys for all your help.

Steve, I think I've tried what you have suggested without any luck as
well... The statement works fine, but what inserted is not correct...
it seems like only the symbol '?' was inserted into the blob field...

I will try the suggested cxOracle library in place of odbc as a
trial... but I think since 95% of the code is using odbc, it would be
hard to convince the team to chance to the new library... anyway, I
will let you know how it goes.

Mar 22 '07 #5
On Mar 23, 4:38 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On 22 Mar 2007 05:36:46 -0700, "Godzilla" <godzillais...@ gmail.com>
declaimed the following in comp.lang.pytho n:
Steve, I think I've tried what you have suggested without any luck as
well... The statement works fine, but what inserted is not correct...
it seems like only the symbol '?' was inserted into the blob field...

You didn't have a set of 's around the ?, did you? Parameter
substitution will add needed quotes on its own rather than you having to
put in quotes.

Also, though I find no documentation on it, odbc module cursors have
setinputsizes() and setoutputsizes( ) methods -- perhaps that could
change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc
module follows) says they may be do-nothing methods.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netc om.com wulfr...@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com)
HTTP://www.bestiaria.com/
Gidday Dennis,

Thank you for your suggestion. I have found those two functions you
mentioned, and there were not much or no documentation for those
functions... I used both function and they pretty much do nothing for
me...

Mar 22 '07 #6
On Mar 23, 4:38 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On 22 Mar 2007 05:36:46 -0700, "Godzilla" <godzillais...@ gmail.com>
declaimed the following in comp.lang.pytho n:
Steve, I think I've tried what you have suggested without any luck as
well... The statement works fine, but what inserted is not correct...
it seems like only the symbol '?' was inserted into the blob field...

You didn't have a set of 's around the ?, did you? Parameter
substitution will add needed quotes on its own rather than you having to
put in quotes.

Also, though I find no documentation on it, odbc module cursors have
setinputsizes() and setoutputsizes( ) methods -- perhaps that could
change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc
module follows) says they may be do-nothing methods.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netc om.com wulfr...@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com)
HTTP://www.bestiaria.com/
Everything seems to work fine right now... thanks all of you for
helping... Have a great day..

Mar 22 '07 #7
Godzilla wrote:
On Mar 23, 4:38 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
>On 22 Mar 2007 05:36:46 -0700, "Godzilla" <godzillais...@ gmail.com>
declaimed the following in comp.lang.pytho n:
>>Steve, I think I've tried what you have suggested without any luck as
well... The statement works fine, but what inserted is not correct...
it seems like only the symbol '?' was inserted into the blob field...
You didn't have a set of 's around the ?, did you? Parameter
substitution will add needed quotes on its own rather than you having to
put in quotes.

Also, though I find no documentation on it, odbc module cursors have
setinputsizes( ) and setoutputsizes( ) methods -- perhaps that could
change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc
module follows) says they may be do-nothing methods.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netc om.com wulfr...@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com)
HTTP://www.bestiaria.com/

Everything seems to work fine right now... thanks all of you for
helping... Have a great day..
Have you any idea what fixed the problem?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #8
On Mar 23, 9:50 am, Steve Holden <s...@holdenweb .comwrote:
Godzilla wrote:
On Mar 23, 4:38 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On 22 Mar 2007 05:36:46 -0700, "Godzilla" <godzillais...@ gmail.com>
declaimed the following in comp.lang.pytho n:
>Steve, I think I've tried what you have suggested without any luck as
well... The statement works fine, but what inserted is not correct...
it seems like only the symbol '?' was inserted into the blob field...
You didn't have a set of 's around the ?, did you? Parameter
substitution will add needed quotes on its own rather than you having to
put in quotes.
Also, though I find no documentation on it, odbc module cursors have
setinputsizes() and setoutputsizes( ) methods -- perhaps that could
change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc
module follows) says they may be do-nothing methods.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netc om.com wulfr...@bestia ria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com)
HTTP://www.bestiaria.com/
Everything seems to work fine right now... thanks all of you for
helping... Have a great day..

Have you any idea what fixed the problem?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com- Hide quoted text -

- Show quoted text -
Hi Steve,

I guess Dennis and yourself pointed me to the right direction; no need
the 's around ? and also the parameter substitution requires tuple.
I.e.:

qry.execute("In sert into tBlob (data) values (?)",
(data.encode('h ex'),))

Thanks again guys... it's been greatly appreciated by the team here as
well.

Mar 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3684
by: ATK | last post by:
Hi, I'm trying to upload a image file to a oracle DB and i need to only use ODBC functions. In db i have a LONG RAW column (if this is not correct, please tell me). I'm getting the error from oracle: ORA-00972: identifier is too long...
6
2360
by: Dan Ellis | last post by:
Hi, I've been down so many dead ends trying to get something working, so I'm really hoping someone can help out. I need to access an Oracle database running on a Windows server from Python running on Linux. I've tried building DCOracle2, but it seems that the 'oracle-installclient-basic' thing I downloaded from the Oracle site doesn't contain enough. I've tried various other approaches, such as mxODBC/iODBC, but without much luck. I'm...
4
10197
by: Morten Goodwin Olsen | last post by:
Python, PostgreSQL and bytea Hi I am having a bit of trouble inserting images into a postgres database using python. The images should be stored in a bytea field. I have tried both with an odbc connection and psycopg. The python code is as following: conn = PgSQL.connect(connectionString) # or psycopg og odb
1
6203
by: X | last post by:
Howdy: To follow up on a problem with MS Access (2000) and Oracle 9i (9.2.0.x) - History: I am trying to import tables from my Oracle 9i database on RedHat Linux 7.2 to MS Access (2000) on NT. I managed to turn on logging / debugging for ODBC connections and I got a few messages that I am unfamiliar with.
11
23045
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
2
4572
by: Chenna Sudarsan | last post by:
Hello, I am connecting to Oracle9.2 database from VB6.0 using MSDAORA provider. I am using ADO2.5. When I try to access a blob column of oracle I am getting the below mentioned error. -------------------- Run-time error '-2147467259 (80004005)': Data type is not supported.
17
2743
by: dananrg | last post by:
I'm a little confused about what's out there for database modules at: http://python.org/topics/database/modules.html What I'd like to do is use Python to access an Oracle 9.X database for exporting a series of tables into one aggregated table as a text file, for import into a mainframe database. The catch is that I'd like to write code that wouldn't need to be changed (much) if we switched from Oracle to some other RDBMS (still need to...
3
9060
by: Gox | last post by:
Hi. This is my situation: Backend: Oracle 8i Frontend: MS Access 2k (ODBC driver support LOBs) Q: How insert (upload) a CLOB (pdf or doc file) to an Oracle using MS access (form)?? Q: How display (download) a CLOB (pdf or doc file) from Oracle using MS access (form)??
2
14259
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers: Additional Array INSERT and SELECT Syntax Support by Pro*C/C++ and Pro*COBOL Precompilers: Dynamic SQL Statement Caching in Pro*C/C++ and Pro*COBOL Precompilers: Fix Execution Plan in Pro*C/C++ and Pro*COBOL Precompilers: Flexible B Area Length...
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.