Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_print.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """ db_print.py -- a simple demo for ADO database reads."""
  2. import sys
  3. import adodbapi.ado_consts as adc
  4. cmd_args = ("filename", "table_name")
  5. if "help" in sys.argv:
  6. print("possible settings keywords are:", cmd_args)
  7. sys.exit()
  8. kw_args = {} # pick up filename and proxy address from command line (optionally)
  9. for arg in sys.argv:
  10. s = arg.split("=")
  11. if len(s) > 1:
  12. if s[0] in cmd_args:
  13. kw_args[s[0]] = s[1]
  14. kw_args.setdefault(
  15. "filename", "test.mdb"
  16. ) # assumes server is running from examples folder
  17. kw_args.setdefault("table_name", "Products") # the name of the demo table
  18. # the server needs to select the provider based on his Python installation
  19. provider_switch = ["provider", "Microsoft.ACE.OLEDB.12.0", "Microsoft.Jet.OLEDB.4.0"]
  20. # ------------------------ START HERE -------------------------------------
  21. # create the connection
  22. constr = "Provider=%(provider)s;Data Source=%(filename)s"
  23. import adodbapi as db
  24. con = db.connect(constr, kw_args, macro_is64bit=provider_switch)
  25. if kw_args["table_name"] == "?":
  26. print("The tables in your database are:")
  27. for name in con.get_table_names():
  28. print(name)
  29. else:
  30. # make a cursor on the connection
  31. with con.cursor() as c:
  32. # run an SQL statement on the cursor
  33. sql = "select * from %s" % kw_args["table_name"]
  34. print('performing query="%s"' % sql)
  35. c.execute(sql)
  36. # check the results
  37. print(
  38. 'result rowcount shows as= %d. (Note: -1 means "not known")' % (c.rowcount,)
  39. )
  40. print("")
  41. print("result data description is:")
  42. print(" NAME Type DispSize IntrnlSz Prec Scale Null?")
  43. for d in c.description:
  44. print(
  45. ("%16s %-12s %8s %8d %4d %5d %s")
  46. % (d[0], adc.adTypeNames[d[1]], d[2], d[3], d[4], d[5], bool(d[6]))
  47. )
  48. print("")
  49. print("str() of first five records are...")
  50. # get the results
  51. db = c.fetchmany(5)
  52. # print them
  53. for rec in db:
  54. print(rec)
  55. print("")
  56. print("repr() of next row is...")
  57. print(repr(c.fetchone()))
  58. print("")
  59. con.close()