本文整理匯總了Python中cx_Oracle.Error方法的典型用法代碼示例。如果您正苦於以下問題:Python cx_Oracle.Error方法的具體用法?Python cx_Oracle.Error怎麽用?Python cx_Oracle.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cx_Oracle
的用法示例。
在下文中一共展示了cx_Oracle.Error方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _setup_environment
# 需要導入模塊: import cx_Oracle [as 別名]
# 或者: from cx_Oracle import Error [as 別名]
def _setup_environment(environ):
# Cygwin requires some special voodoo to set the environment variables
# properly so that Oracle will see them.
if platform.system().upper().startswith('CYGWIN'):
try:
import ctypes
except ImportError as e:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("Error loading ctypes: %s; "
"the Oracle backend requires ctypes to "
"operate correctly under Cygwin." % e)
kernel32 = ctypes.CDLL('kernel32')
for name, value in environ:
kernel32.SetEnvironmentVariableA(name, value)
else:
os.environ.update(environ)
示例2: db_connect
# 需要導入模塊: import cx_Oracle [as 別名]
# 或者: from cx_Oracle import Error [as 別名]
def db_connect(args):
if args.type == "mysql" or args.type == "mariadb":
import mysql.connector
try:
connection = mysql.connector.connect(
user=args.user,
password=args.password,
database=args.db)
except mysql.connector.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "mssql":
import pymssql
try:
connection = pymssql.connect(server="localhost", database=args.db)
except pymssql.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "pgsql":
import psycopg2
try:
connection = psycopg2.connect(
"dbname='{}' user='{}' password='{}'".format(
args.db, args.user, args.password))
except psycopg2.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "oracle":
import cx_Oracle
try:
connection = cx_Oracle.connect(
args.user, args.password, cx_Oracle.makedsn(
'127.0.0.1', 1521, args.db), mode=cx_Oracle.SYSDBA)
except cx_Oracle.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
return connection
示例3: is_usable
# 需要導入模塊: import cx_Oracle [as 別名]
# 或者: from cx_Oracle import Error [as 別名]
def is_usable(self):
try:
self.connection.ping()
except Database.Error:
return False
else:
return True
示例4: _setup_environment
# 需要導入模塊: import cx_Oracle [as 別名]
# 或者: from cx_Oracle import Error [as 別名]
def _setup_environment(environ):
# Cygwin requires some special voodoo to set the environment variables
# properly so that Oracle will see them.
if platform.system().upper().startswith('CYGWIN'):
try:
import ctypes
except ImportError as e:
raise ImproperlyConfigured("Error loading ctypes: %s; "
"the Oracle backend requires ctypes to "
"operate correctly under Cygwin." % e)
kernel32 = ctypes.CDLL('kernel32')
for name, value in environ:
kernel32.SetEnvironmentVariableA(name, value)
else:
os.environ.update(environ)