完善错误提示,正确显示oracle提示错误信息
diff --git a/v2convert.py b/v2convert.py
index 4c09bd2..5267a16 100755
--- a/v2convert.py
+++ b/v2convert.py
@@ -7,11 +7,12 @@
import json
import locale
import time
+import cx_Oracle
from path import path
import re
-VERSION = "1.1"
+VERSION = "1.3"
SYSENCODING = locale.getdefaultlocale()[1]
if not SYSENCODING:
@@ -82,7 +83,7 @@
sys.exit(1)
current = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- print "启动转换程序 Version: {0}, {1}".format(VERSION, current)
+ print u"启动转换程序 Version: {0}, {1}".format(VERSION, current)
if not self._load_convert_file():
self.die(u"不能加载转换规则文件")
@@ -151,8 +152,17 @@
return True
return True
- except Exception as e:
- print u"执行sql 失败, {0}".format(e)
+ except Exception as exc:
+ try:
+ if isinstance(exc, cx_Oracle.DatabaseError):
+ error, = exc.args
+ msg = error.message.decode(SYSENCODING)
+ else:
+ msg = "{0}".format(exc)
+ print u"执行sql 失败, {0}".format(msg)
+ except UnicodeError:
+ print exc
+ print u"执行语句[{0}]错误".format(statment)
return False
def _do_convert(self, rule):
@@ -193,10 +203,12 @@
insert_sql = 'insert into {0} ({1}) values({2})'.format(rule['name'],
rule['dest_column'], values)
# print insert_sql
+ count += 1
if not self._dst_db.exec_sql(insert_sql):
+ print u"导入第{0}条记录错误".format(count)
self._dst_db.rollback()
return False
- count += 1
+
if count % self._commit_count == 0:
print u"导入数据 {0} 条".format(count)
self._dst_db.commit()