From: Kevin A. <ka...@us...> - 2004-05-09 23:58:19
|
Update of /cvsroot/pythoncard/PythonCard/samples/dbBrowser/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9019/samples/dbBrowser/scripts Modified Files: gadfly_sample.py mysql_sample.py Log Message: fixed rogue lines ending in just a carriage return Index: mysql_sample.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/dbBrowser/scripts/mysql_sample.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mysql_sample.py 21 Aug 2001 12:07:46 -0000 1.1 --- mysql_sample.py 9 May 2004 23:58:09 -0000 1.2 *************** *** 1,89 **** ! #!/usr/bin/python ! # Usage: python mysql_sample.py <username> <password> ! # ! # If you do not specify a username and a password then you will need ! # to have 'open' access to your local MySQL database. ! # ! # This script kind of assumes you are one Windows. With the Windows binary ! # distribution of MySQL you get two databases 'for free', one called MYSQL ! # and another called 'test'. We create the tables in 'test' if the user does ! # not specify a database name. If there is no database called 'test' on *nix ! # then we are in trouble. ! # ! import MySQLdb, sys ! ! # Specify some default values ! usageString="Usage: python %s <username> <password> <db name>" % sys.argv[0] ! dbName='test' ! ! if __name__=="__main__": ! if len(sys.argv) > 1: ! if sys.argv[1] in ("-h","--help"): ! print usageString ! sys.exit(0) ! if sys.argv[3]: ! # There is a database name on the command line ! dbName=sys.argv[3] ! # We assume arguments 1 and 2 are username and password ! try: ! db=MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=dbName) ! except MySQLdb.OperationalError: ! print usageString ! print "Invalid username, password or db name, please try again" ! sys.exit(1) ! else: ! # Free entry for all ! try: ! db=MySQLdb.connect(db=dbName) ! except MySQLdb.OperationalError: ! print usageString ! print "You cannot connect to the 'test' database without a valid username and password" ! sys.exit(1) ! # We have connected to a database now, lets issue some SQL ! # There is no error handling here, if anything goes wrong exceptions ! # will be raised by the MySQLdb package ! cursor=db.cursor() ! stmt=""" ! CREATE TABLE currencies ! ( currency_code VARCHAR(3) NOT NULL ! ,currency_desc VARCHAR(255) ! ,PRIMARY KEY ( currency_code ) ! ) ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! INSERT INTO currencies ! ( currency_code, currency_desc ) ! VALUES ! ( 'USD', 'US Dollars'), ! ( 'AUD', 'Australian Dollars'), ! ( 'UKP', 'Pounds Sterling'), ! ( 'FFR', 'French Francs'), ! ( 'HKD', 'Hong Kong Dollar'), ! ( 'CHF', 'Swiss Franc'), ! ( 'CAD', 'Canadian Dollar'), ! ( 'VND', 'Vietnamese Dong') ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! CREATE TABLE exchange_rates ! ( exchange_date DATE NOT NULL ! ,currency_from VARCHAR(3) NOT NULL ! ,currency_to VARCHAR(3) NOT NULL ! ,exchange_rate NUMERIC(15,3) ! ) ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! INSERT INTO exchange_rates ! ( exchange_date, currency_from, currency_to, exchange_rate ) ! VALUES ! ( '2001-08-01', 'USD', 'AUD', 1.869 ), ! ( '2001-08-01', 'USD', 'UKP', 0.750 ), ! ( '2001-08-01', 'UKP', 'HKD', 11.02 ) ! """ ! result=cursor.execute(stmt) ! --- 1,89 ---- ! #!/usr/bin/python ! # Usage: python mysql_sample.py <username> <password> ! # ! # If you do not specify a username and a password then you will need ! # to have 'open' access to your local MySQL database. ! # ! # This script kind of assumes you are one Windows. With the Windows binary ! # distribution of MySQL you get two databases 'for free', one called MYSQL ! # and another called 'test'. We create the tables in 'test' if the user does ! # not specify a database name. If there is no database called 'test' on *nix ! # then we are in trouble. ! # ! import MySQLdb, sys ! ! # Specify some default values ! usageString="Usage: python %s <username> <password> <db name>" % sys.argv[0] ! dbName='test' ! ! if __name__=="__main__": ! if len(sys.argv) > 1: ! if sys.argv[1] in ("-h","--help"): ! print usageString ! sys.exit(0) ! if sys.argv[3]: ! # There is a database name on the command line ! dbName=sys.argv[3] ! # We assume arguments 1 and 2 are username and password ! try: ! db=MySQLdb.connect(user=sys.argv[1], passwd=sys.argv[2], db=dbName) ! except MySQLdb.OperationalError: ! print usageString ! print "Invalid username, password or db name, please try again" ! sys.exit(1) ! else: ! # Free entry for all ! try: ! db=MySQLdb.connect(db=dbName) ! except MySQLdb.OperationalError: ! print usageString ! print "You cannot connect to the 'test' database without a valid username and password" ! sys.exit(1) ! # We have connected to a database now, lets issue some SQL ! # There is no error handling here, if anything goes wrong exceptions ! # will be raised by the MySQLdb package ! cursor=db.cursor() ! stmt=""" ! CREATE TABLE currencies ! ( currency_code VARCHAR(3) NOT NULL ! ,currency_desc VARCHAR(255) ! ,PRIMARY KEY ( currency_code ) ! ) ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! INSERT INTO currencies ! ( currency_code, currency_desc ) ! VALUES ! ( 'USD', 'US Dollars'), ! ( 'AUD', 'Australian Dollars'), ! ( 'UKP', 'Pounds Sterling'), ! ( 'FFR', 'French Francs'), ! ( 'HKD', 'Hong Kong Dollar'), ! ( 'CHF', 'Swiss Franc'), ! ( 'CAD', 'Canadian Dollar'), ! ( 'VND', 'Vietnamese Dong') ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! CREATE TABLE exchange_rates ! ( exchange_date DATE NOT NULL ! ,currency_from VARCHAR(3) NOT NULL ! ,currency_to VARCHAR(3) NOT NULL ! ,exchange_rate NUMERIC(15,3) ! ) ! """ ! result=cursor.execute(stmt) ! ! stmt=""" ! INSERT INTO exchange_rates ! ( exchange_date, currency_from, currency_to, exchange_rate ) ! VALUES ! ( '2001-08-01', 'USD', 'AUD', 1.869 ), ! ( '2001-08-01', 'USD', 'UKP', 0.750 ), ! ( '2001-08-01', 'UKP', 'HKD', 11.02 ) ! """ ! result=cursor.execute(stmt) ! Index: gadfly_sample.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/dbBrowser/scripts/gadfly_sample.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gadfly_sample.py 29 Jan 2003 15:38:02 -0000 1.1 --- gadfly_sample.py 9 May 2004 23:58:09 -0000 1.2 *************** *** 1,80 **** ! #!/usr/bin/python ! # Usage: python gadfly_sample.py <databaseName> <databaseDirectory> ! # ! # Based on the mysql_sample.py script shipped with the PythonCard dbBrowser sample ! __author__ = "Andy Todd <an...@ha...>" ! ! import gadfly, sys ! ! # Specify some default values ! usageString="Usage: python %s <databaseName> <databaseDirectory>" % sys.argv[0] ! ! if __name__=="__main__": ! if len(sys.argv) > 1: ! if sys.argv[1] in ("-h","--help") or len(sys.argv) != 3: ! print usageString ! sys.exit(0) ! # There is a database name on the command line ! dbName=sys.argv[1] ! dbDir=sys.argv[2] ! # If the database doesn't already exist we need to create it ! try: ! db=gadfly.gadfly(dbName, dbDir) ! except IOError: ! print "Database %s doesn't exist, creating it ..." % dbName ! db=gadfly.gadfly() ! db.startup(dbName, dbDir) ! ! # We have connected to a database now, lets issue some SQL ! # There is no error handling here, if anything goes wrong exceptions ! # will be raised by the MySQLdb package ! cursor=db.cursor() ! stmt=""" ! CREATE TABLE currencies ! ( currency_code VARCHAR(3) ! ,currency_desc VARCHAR(255) ! ) ! """ ! result=cursor.execute(stmt) ! db.commit() ! stmt="""CREATE UNIQUE INDEX currency_pk ON currencies(currency_code)""" ! result=cursor.execute(stmt) ! db.commit() ! ! stmt=""" ! INSERT INTO currencies ! ( currency_code, currency_desc ) ! VALUES ! ( ?, ? )""" ! cursor.execute(stmt, ( 'USD', 'US Dollars')) ! cursor.execute(stmt, ( 'AUD', 'Australian Dollars')) ! cursor.execute(stmt, ( 'UKP', 'Pounds Sterling')) ! cursor.execute(stmt, ( 'FFR', 'French Francs')) ! cursor.execute(stmt, ( 'HKD', 'Hong Kong Dollar')) ! cursor.execute(stmt, ( 'CHF', 'Swiss Franc')) ! cursor.execute(stmt, ( 'CAD', 'Canadian Dollar')) ! cursor.execute(stmt, ( 'VND', 'Vietnamese Dong')) ! db.commit() ! ! stmt=""" ! CREATE TABLE exchange_rates ! ( exchange_date VARCHAR ! ,currency_from VARCHAR(3) ! ,currency_to VARCHAR(3) ! ,exchange_rate FLOAT ! ) ! """ ! result=cursor.execute(stmt) ! db.commit() ! ! stmt=""" ! INSERT INTO exchange_rates ! ( exchange_date, currency_from, currency_to, exchange_rate ) ! VALUES ! ( ?, ?, ?, ? ) ! """ ! cursor.execute(stmt, ( '2001-08-01', 'USD', 'AUD', 1.869 )) ! cursor.execute(stmt, ( '2001-08-01', 'USD', 'UKP', 0.750 )) ! cursor.execute(stmt, ( '2001-08-01', 'UKP', 'HKD', 11.02 )) ! db.commit() ! --- 1,80 ---- ! #!/usr/bin/python ! # Usage: python gadfly_sample.py <databaseName> <databaseDirectory> ! # ! # Based on the mysql_sample.py script shipped with the PythonCard dbBrowser sample ! __author__ = "Andy Todd <an...@ha...>" ! ! import gadfly, sys ! ! # Specify some default values ! usageString="Usage: python %s <databaseName> <databaseDirectory>" % sys.argv[0] ! ! if __name__=="__main__": ! if len(sys.argv) > 1: ! if sys.argv[1] in ("-h","--help") or len(sys.argv) != 3: ! print usageString ! sys.exit(0) ! # There is a database name on the command line ! dbName=sys.argv[1] ! dbDir=sys.argv[2] ! # If the database doesn't already exist we need to create it ! try: ! db=gadfly.gadfly(dbName, dbDir) ! except IOError: ! print "Database %s doesn't exist, creating it ..." % dbName ! db=gadfly.gadfly() ! db.startup(dbName, dbDir) ! ! # We have connected to a database now, lets issue some SQL ! # There is no error handling here, if anything goes wrong exceptions ! # will be raised by the MySQLdb package ! cursor=db.cursor() ! stmt=""" ! CREATE TABLE currencies ! ( currency_code VARCHAR(3) ! ,currency_desc VARCHAR(255) ! ) ! """ ! result=cursor.execute(stmt) ! db.commit() ! stmt="""CREATE UNIQUE INDEX currency_pk ON currencies(currency_code)""" ! result=cursor.execute(stmt) ! db.commit() ! ! stmt=""" ! INSERT INTO currencies ! ( currency_code, currency_desc ) ! VALUES ! ( ?, ? )""" ! cursor.execute(stmt, ( 'USD', 'US Dollars')) ! cursor.execute(stmt, ( 'AUD', 'Australian Dollars')) ! cursor.execute(stmt, ( 'UKP', 'Pounds Sterling')) ! cursor.execute(stmt, ( 'FFR', 'French Francs')) ! cursor.execute(stmt, ( 'HKD', 'Hong Kong Dollar')) ! cursor.execute(stmt, ( 'CHF', 'Swiss Franc')) ! cursor.execute(stmt, ( 'CAD', 'Canadian Dollar')) ! cursor.execute(stmt, ( 'VND', 'Vietnamese Dong')) ! db.commit() ! ! stmt=""" ! CREATE TABLE exchange_rates ! ( exchange_date VARCHAR ! ,currency_from VARCHAR(3) ! ,currency_to VARCHAR(3) ! ,exchange_rate FLOAT ! ) ! """ ! result=cursor.execute(stmt) ! db.commit() ! ! stmt=""" ! INSERT INTO exchange_rates ! ( exchange_date, currency_from, currency_to, exchange_rate ) ! VALUES ! ( ?, ?, ?, ? ) ! """ ! cursor.execute(stmt, ( '2001-08-01', 'USD', 'AUD', 1.869 )) ! cursor.execute(stmt, ( '2001-08-01', 'USD', 'UKP', 0.750 )) ! cursor.execute(stmt, ( '2001-08-01', 'UKP', 'HKD', 11.02 )) ! db.commit() ! |