您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

99 行
2.4 KiB

  1. :mod:`db` --- Database
  2. ======================
  3. .. module:: db
  4. :synopsis: Database Module
  5. database object --- conn
  6. ------------------------
  7. .. class:: Database(host='', user='', password='', use_default = 0):
  8. Open a database connection with the given parmeters, if use_default is True, use the
  9. login details from `defs.py`. This is called by the request handler and is accessible using
  10. the `conn` global variable. the `sql` method is also global to run queries
  11. .. attribute:: host
  12. Database host or 'localhost'
  13. .. attribute:: user
  14. Database user
  15. .. attribute:: password
  16. Database password - cleared after connection is made
  17. .. attribute:: is_testing
  18. 1 if session is in `Testing Mode` else 0
  19. .. attribute:: in_transaction
  20. 1 if connection is in a Transaction else 0
  21. .. attribute:: testing_tables
  22. list of tables, tables with `tab` + doctype
  23. .. method:: connect()
  24. Connect to a database
  25. .. method:: use(db_name)
  26. `USE` db_name
  27. .. method:: set_db(account)
  28. Switch to database of given `account`
  29. .. method:: check_transaction_status(query)
  30. Update *in_transaction* and check if "START TRANSACTION" is not called twice
  31. .. method:: fetch_as_dict()
  32. Internal - get results as dictionary
  33. .. method:: sql(query, values=(), as_dict = 0, as_list = 0, allow_testing = 1)
  34. * Execute a `query`, with given `values`
  35. * returns as a dictionary if as_dict = 1
  36. * returns as a list of lists (with cleaned up dates and decimals) if as_list = 1
  37. .. method:: convert_to_lists(res)
  38. Convert the given result set to a list of lists (with cleaned up dates and decimals)
  39. .. method:: replace_tab_by_test(query)
  40. Relace all ``tab`` + doctype to ``test`` + doctype
  41. .. method:: get_testing_tables()
  42. Get list of all tables for which `tab` is to be replaced by `test` before a query is executed
  43. .. method:: get_value(doctype, docname, fieldname)
  44. Get a single value from a record.
  45. For Single records, let docname be = None
  46. .. method:: get_description()
  47. Get metadata of the last query
  48. .. method:: field_exists(dt, fn)
  49. Returns True if `fn` exists in `DocType` `dt`
  50. .. method:: exists(dt, dn)
  51. Returns true if the record exists
  52. .. method:: close()
  53. Close my connection