Guest User

Untitled

a guest
Feb 13th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. create_table = """
  2. DROP TABLE IF EXISTS `dec_test`;
  3. CREATE TABLE `dec_test` (
  4. `dec_2_2` decimal(4,2),
  5. `dec_4_2` decimal(6,2),
  6. `dec_8_4` decimal(8,4),
  7. `char_15` char(15)
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  9.  
  10. insert into dec_test values
  11. (1, 1, 1, 1),
  12. (1.1, 1.1, 1.1, 1.1),
  13. (1.11, 1.11, 1.11, 1.11),
  14. (1.111, 1.111, 1.111, 1.111),
  15. (1.1111, 1.1111, 1.1111, 1.1111),
  16. (1.11111, 1.11111, 1.11111, 1.11111),
  17. (11.11111, 11.11111, 11.11111, 11.11111),
  18. (NULL, 111.11111, 111.11111, 111.11111), -- too large values cause error
  19. (NULL, 1111.11111, 1111.11111, 1111.11111),
  20. (NULL, NULL, NULL, 11111.11111)
  21. ;
  22. """
  23.  
  24. # pymysql
  25. import pymysql
  26.  
  27. conn = pymysql.connect(host='127.0.0.1',
  28. user='user',
  29. password='password',
  30. db='test')
  31.  
  32. cur = conn.cursor()
  33. cur.execute('select * from dec_test')
  34. cur.fetchall()
  35. d1 = cur.description
  36. cur.close()
  37. conn.close()
  38.  
  39. # mysqldb
  40.  
  41. import MySQLdb
  42.  
  43. conn = MySQLdb.connect(host='127.0.0.1',
  44. user='user',
  45. passwd='password',
  46. db='test')
  47.  
  48. cur = conn.cursor()
  49. cur.execute('select * from dec_test')
  50. cur.fetchall()
  51. d2 = cur.description
  52. cur.close()
  53. conn.close()
  54.  
  55. # MySQL Connector/Python
  56.  
  57. import mysql.connector
  58.  
  59. conn = mysql.connector.connect(host='127.0.0.1',
  60. user='user',
  61. password='password',
  62. database='test')
  63.  
  64. cur = conn.cursor()
  65. cur.execute('select * from dec_test')
  66. cur.fetchall()
  67. d3 = cur.description
  68. cur.close()
  69. conn.close()
  70.  
  71. print d1
  72. print d2
  73. print d3
  74.  
  75. """ Output:
  76. ((u'dec_2_2', 246, None, 6, 6, 2, True),
  77. (u'dec_4_2', 246, None, 8, 8, 2, True),
  78. (u'dec_8_4', 246, None, 10, 10, 4, True),
  79. (u'char_15', 254, None, 15, 15, 0, True))
  80.  
  81. (('dec_2_2', 246, 5, 6, 6, 2, 1),
  82. ('dec_4_2', 246, 7, 8, 8, 2, 1),
  83. ('dec_8_4', 246, 9, 10, 10, 4, 1),
  84. ('char_15', 254, 11, 45, 45, 0, 1))
  85.  
  86. [(u'dec_2_2', 246, None, None, None, None, 1, 0),
  87. (u'dec_4_2', 246, None, None, None, None, 1, 0),
  88. (u'dec_8_4', 246, None, None, None, None, 1, 0),
  89. (u'char_15', 254, None, None, None, None, 1, 0)]
  90. """
Add Comment
Please, Sign In to add comment