| Trees | Indices | Help |
|
|---|
|
|
1 # -*- coding: utf-8 -*- 2 # 3 # Copyright (C) 2010-2020 Edgewall Software 4 # All rights reserved. 5 # 6 # This software is licensed as described in the file COPYING, which 7 # you should have received as part of this distribution. The terms 8 # are also available at https://trac.edgewall.org/wiki/TracLicense. 9 # 10 # This software consists of voluntary contributions made by many 11 # individuals. For the exact contribution history, see the revision 12 # history and logs, available at https://trac.edgewall.org/log/. 13 14 import unittest 15 16 import trac.tests.compat 17 from trac.db.mysql_backend import MySQLConnector 18 from trac.db.schema import Table, Column, Index 19 from trac.test import EnvironmentStub, Mock 20 212580 8127 connector = MySQLConnector(self.env) 28 sql = connector.alter_column_types('milestone', 29 {'due': ('int', 'int64'), 30 'completed': ('int', 'int64')}) 31 sql = list(sql) 32 self.assertEqual([ 33 "ALTER TABLE milestone " 34 "MODIFY completed bigint, " 35 "MODIFY due bigint", 36 ], sql)3739 connector = MySQLConnector(self.env) 40 sql = connector.alter_column_types('milestone', 41 {'due': ('int', 'int'), 42 'completed': ('int', 'int64')}) 43 sql = list(sql) 44 self.assertEqual([ 45 "ALTER TABLE milestone " 46 "MODIFY completed bigint", 47 ], sql)4850 connector = MySQLConnector(self.env) 51 sql = connector.alter_column_types('milestone', 52 {'due': ('int', 'int')}) 53 self.assertEqual([], list(sql))5456 connector = MySQLConnector(self.env) 57 self.assertEqual(3, connector._max_bytes(Mock(charset='utf8'))) 58 self.assertEqual(4, connector._max_bytes(Mock(charset='utf8mb4')))5961 connector = MySQLConnector(self.env) 62 tab = Table('blah', key=('col1', 'col2', 'col3', 'col4', 'col5')) \ 63 [Column('col1'), Column('col2'), Column('col3'), Column('col4'), 64 Column('col5'), Column('col6'), 65 Index(['col2', 'col3', 'col4', 'col5'])] 66 67 sql = list(connector.to_sql(tab, max_bytes=3)) 68 self.assertEqual(2, len(sql)) 69 self.assertIn(' PRIMARY KEY (`col1`(204),`col2`(204),`col3`(204),' 70 '`col4`(204),`col5`(204))', sql[0]) 71 self.assertIn(' `blah_col2_col3_col4_col5_idx` ON `blah` (`col2`(255),' 72 '`col3`(255),`col4`(255),`col5`(255))', sql[1]) 73 74 sql = list(connector.to_sql(tab, max_bytes=4)) 75 self.assertEqual(2, len(sql)) 76 self.assertIn(' PRIMARY KEY (`col1`(153),`col2`(153),`col3`(153),' 77 '`col4`(153),`col5`(153))', sql[0]) 78 self.assertIn(' `blah_col2_col3_col4_col5_idx` ON `blah` (`col2`(191),' 79 '`col3`(191),`col4`(191),`col5`(191))', sql[1])83 suite = unittest.TestSuite() 84 suite.addTest(unittest.makeSuite(MySQLTableAlterationSQLTest)) 85 return suite86 87 88 if __name__ == '__main__': 89 unittest.main(defaultTest='suite') 90
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Wed Jul 5 01:52:14 2023 | http://epydoc.sourceforge.net |