Ensure these files have native line endings on all platforms.

This commit is contained in:
Anthony Tuininga 2007-10-02 02:58:33 +00:00
parent a9aa846872
commit e2ea889ff9
3 changed files with 83 additions and 83 deletions

View File

@ -1,24 +1,24 @@
#------------------------------------------------------------------------------
# DatabaseShutdown.py
# This script demonstrates shutting down a database using Python. It is only
# possible in Oracle 10g Release 2 and higher. The connection used assumes that
# the environment variable ORACLE_SID has been set.
#------------------------------------------------------------------------------
import cx_Oracle
# need to connect as SYSDBA or SYSOPER
connection = cx_Oracle.connect("/", mode = cx_Oracle.SYSDBA)
# first shutdown() call must specify the mode, if DBSHUTDOWN_ABORT is used,
# there is no need for any of the other steps
connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_IMMEDIATE)
# now close and dismount the database
cursor = connection.cursor()
cursor.execute("alter database close normal")
cursor.execute("alter database dismount")
# perform the final shutdown call
connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_FINAL)
#------------------------------------------------------------------------------
# DatabaseShutdown.py
# This script demonstrates shutting down a database using Python. It is only
# possible in Oracle 10g Release 2 and higher. The connection used assumes that
# the environment variable ORACLE_SID has been set.
#------------------------------------------------------------------------------
import cx_Oracle
# need to connect as SYSDBA or SYSOPER
connection = cx_Oracle.connect("/", mode = cx_Oracle.SYSDBA)
# first shutdown() call must specify the mode, if DBSHUTDOWN_ABORT is used,
# there is no need for any of the other steps
connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_IMMEDIATE)
# now close and dismount the database
cursor = connection.cursor()
cursor.execute("alter database close normal")
cursor.execute("alter database dismount")
# perform the final shutdown call
connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_FINAL)

View File

@ -1,20 +1,20 @@
#------------------------------------------------------------------------------
# DatabaseStartup.py
# This script demonstrates starting up a database using Python. It is only
# possible in Oracle 10g Release 2 and higher. The connection used assumes that
# the environment variable ORACLE_SID has been set.
#------------------------------------------------------------------------------
import cx_Oracle
# the connection must be in PRELIM_AUTH mode
connection = cx_Oracle.connect("/",
mode = cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH)
connection.startup()
# the following statements must be issued in normal SYSDBA mode
connection = cx_Oracle.connect("/", mode = cx_Oracle.SYSDBA)
cursor = connection.cursor()
cursor.execute("alter database mount")
cursor.execute("alter database open")
#------------------------------------------------------------------------------
# DatabaseStartup.py
# This script demonstrates starting up a database using Python. It is only
# possible in Oracle 10g Release 2 and higher. The connection used assumes that
# the environment variable ORACLE_SID has been set.
#------------------------------------------------------------------------------
import cx_Oracle
# the connection must be in PRELIM_AUTH mode
connection = cx_Oracle.connect("/",
mode = cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH)
connection.startup()
# the following statements must be issued in normal SYSDBA mode
connection = cx_Oracle.connect("/", mode = cx_Oracle.SYSDBA)
cursor = connection.cursor()
cursor.execute("alter database mount")
cursor.execute("alter database open")

View File

@ -1,39 +1,39 @@
#------------------------------------------------------------------------------
# RowsAsInstance.py
# Returns rows as instances instead of tuples. See the ceDatabase.Row class
# in the cx_PyGenLib project (http://cx-pygenlib.sourceforge.net) for a more
# advanced example.
#------------------------------------------------------------------------------
import cx_Oracle
class Test(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
connection = cx_Oracle.Connection("cx_Oracle/password")
cursor = connection.cursor()
# change this to True if you want to create the table, or create it using
# SQL*Plus instead; populate it with the data of your choice
if False:
cursor.execute("""
create table TestInstances (
a varchar2(60) not null,
b number(9) not null,
c date not null
)""")
cursor.execute("insert into TestInstances values ('First', 5, sysdate)")
cursor.execute("insert into TestInstances values ('Second', 25, sysdate)")
connection.commit()
# retrieve the data and display it
cursor.execute("select * from TestInstances")
cursor.rowfactory = Test
print "Rows:"
for row in cursor:
print "a = %s, b = %s, c = %s" % (row.a, row.b, row.c)
#------------------------------------------------------------------------------
# RowsAsInstance.py
# Returns rows as instances instead of tuples. See the ceDatabase.Row class
# in the cx_PyGenLib project (http://cx-pygenlib.sourceforge.net) for a more
# advanced example.
#------------------------------------------------------------------------------
import cx_Oracle
class Test(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
connection = cx_Oracle.Connection("cx_Oracle/password")
cursor = connection.cursor()
# change this to True if you want to create the table, or create it using
# SQL*Plus instead; populate it with the data of your choice
if False:
cursor.execute("""
create table TestInstances (
a varchar2(60) not null,
b number(9) not null,
c date not null
)""")
cursor.execute("insert into TestInstances values ('First', 5, sysdate)")
cursor.execute("insert into TestInstances values ('Second', 25, sysdate)")
connection.commit()
# retrieve the data and display it
cursor.execute("select * from TestInstances")
cursor.rowfactory = Test
print "Rows:"
for row in cursor:
print "a = %s, b = %s, c = %s" % (row.a, row.b, row.c)