cx-oracle

Pass encoding parameter to cx_oracle from sqlalchemy

强颜欢笑 提交于 2019-12-05 18:43:59
I'm using Oracle Database with UTF-16 encoding. The diacritics is correctly displayed when using directly cx_oracle client. Connection statement is like this: cx_Oracle.connect(username, password, conn_str, encoding='UTF-16', nencoding='UTF-16') However, now I'm building bigger application and I would like to use SQLalchemy in Flask . Code looks like this: from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy(app) db.Model.metadata.reflect(db.engine) class MyTable(db.Model): __table__ = db.Model.metadata.tables['mytable'] for row in MyTable.query: print(row.column_with_diacritics) Output of

Python - write headers to csv

与世无争的帅哥 提交于 2019-12-05 16:50:52
Currently i am writing query in python which export data from oracle dbo to .csv file. I am not sure how to write headers within file. try: connection = cx_Oracle.connect('user','pass','tns_name') cursor = connection.cursor() print "connected" try: query = """select * from """ .format(line_name) tmp = cursor.execute(query) results = tmp.fetchall() except: pass except: print IOError filename='{0}.csv'.format(line_name) csv_file = open(filename,'wb') if results: myFile = csv.writer(csv_file) myFile.writerows(results) else: print "null" csv_file.close() you can ethier do this after executing your

How to change environment variables in python?

浪子不回头ぞ 提交于 2019-12-05 16:48:59
i have a simple python script ( test.py ): import cx_Oracle from cx_Oracle tns = cx_Oracle.makedsn('10.10.1.3', 1521, 'etst') db = cx_Oracle.connect('test', 'test', tns) it is work if I run script with enviroument settings: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ./test.py Can I set environment variables in python script ? os.environ['LD_LIBRARY_PATH'] = "/usr/lib/oracle/11.2/client64/lib" os.putenv('LD_LIBRARY_PATH', "/usr/lib/oracle/11.2/client64/lib/") not work. You can set them that way, however $LD_LIBRARY_PATH is read by the loader which has already run before that

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

别等时光非礼了梦想. 提交于 2019-12-05 12:38:22
问题 I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access. I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first. The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using: DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password') Can Python do

Inserting a CLOB using cx_Oracle

流过昼夜 提交于 2019-12-05 09:49:31
I am trying to insert a CLOB using the following code. cursor = connection.cursor() cursor.setinputsizes(HERP = cx_Oracle.CLOB) cursor.execute("INSERT INTO myTable (FOO, BAR) VALUES (:FOO, :BAR)", FOO=val1, BAR=val2) cursor.execute("INSERT INTO myTable2 (HERP) VALUES (:HERP)", HERP=val3) #len(HERP) 39097 When I run the script WITHOUT cursor.setinputsizes(HERP = cx_Oracle.CLOB) it fails on the second query WITH ValueError: string data too large , when I run the script with cursor.setinputsizes(HERP = cx_Oracle.CLOB) it fails on the first query with DatabaseError: ORA-01036: illegal variable

cx_Oracle 'ORA-01843: not a valid month' with unicode parameter

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 09:39:49
I have the following: (using ipython) In [30]: con = cx_Oracle.connect('refill_test02/******@MYDB') In [31]: cur = con.cursor() In [32]: cur.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") In [33]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", ['2013-03-12', '2013-03-12 08:22:31.332144']) Out[33]: <__builtin__.OracleCursor on <cx_Oracle.Connection to refill_test02@MYDB>> In [34]: cur.fetchall() Out[34]: [(datetime.datetime(2013, 3, 12, 0, 0), datetime.datetime(2013, 3, 12, 8, 22, 31, 332144))] In [35]: cur

“error: cannot locate an Oracle software installation” When trying to install cx_Oracle

馋奶兔 提交于 2019-12-05 00:21:14
Newbie here trying to use python to do some database analysis. I keep getting the error: "error: cannot locate an Oracle software installation" When installing CX_oracle (via easy_install). The problem is I do not have oracle on my local machine, I'm trying to use python to connect to the main oracle server. I have have setup another program to do this(visualdb) and I had a .jar file I used as the driver but I'm not sure how to use it in this case. Any suggestions? Silas Ray Don't use easy_install or pip, they don't really work very well for installing cx_Oracle since there are a number of

Fetching huge data from Oracle in Python

前提是你 提交于 2019-12-04 23:29:42
I need to fetch huge data from Oracle (using cx_oracle) in python 2.6, and to produce some csv file. The data size is about 400k record x 200 columns x 100 chars each. Which is the best way to do that? Now, using the following code... ctemp = connection.cursor() ctemp.execute(sql) ctemp.arraysize = 256 for row in ctemp: file.write(row[1]) ... ... the script remain hours in the loop and nothing is writed to the file... (is there a way to print a message for every record extracted?) Note: I don't have any issue with Oracle, and running the query in SqlDeveloper is super fast. Thank you, gian You

cx_Oracle: How can I receive each row as a dictionary?

▼魔方 西西 提交于 2019-12-04 18:55:21
问题 By default, cx_Oracle returns each row as a tuple. >>> import cx_Oracle >>> conn=cx_Oracle.connect('scott/tiger') >>> curs=conn.cursor() >>> curs.execute("select * from foo"); >>> curs.fetchone() (33, 'blue') How can I return each row as a dictionary? 回答1: You can override the cursor's rowfactory method. You will need to do this each time you perform the query. Here's the results of the standard query, a tuple. curs.execute('select * from foo') curs.fetchone() (33, 'blue') Returning a named

How to connect to Oracle in go

自闭症网瘾萝莉.ら 提交于 2019-12-04 17:54:04
问题 I gather there are two ways to connect to Oracle DB in Go (on windows): github.com/tgulacsi/goracle github.com/mattn/go-oci8 But for someone of my level (beginner in open source+golang), those two methods/drivers are awfully tricky. It's also a burden having to go through all of that for deployment, development on different machines etc. (Also assuming it will work). Is there a better way to connect to Oracle db in golang or if there is not then can someone explain to me in high level view or