1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  | 
<?php
Prado::using('System.Data.*');
Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
class MysqlColumnTest extends UnitTestCase
{
	function create_meta_data()
	{
		$conn = new TDbConnection('mysql:host=localhost;dbname=tests;port=3307', 'test5','test5');
		return new TMysqlMetaData($conn);
	}
	function test_columns()
	{
		$table = $this->create_meta_data()->getTableInfo('table1');
		$this->assertEqual(count($table->getColumns()), 18);
		$columns['id'] = array(
			'ColumnName'       => '`id`',
			'ColumnSize'       => 10,
			'ColumnIndex'      => 0,
			'DbType'           => 'int unsigned',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => true,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => true,
		);
		$columns['name'] = array(
			'ColumnName'       => '`name`',
			'ColumnSize'       => 45,
			'ColumnIndex'      => 1,
			'DbType'           => 'varchar',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => true,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field1'] = array(
			'ColumnName'       => '`field1`',
			'ColumnSize'       => 4,
			'ColumnIndex'      => 2,
			'DbType'           => 'tinyint',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field2_text'] = array(
			'ColumnName'       => '`field2_text`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 3,
			'DbType'           => 'text',
			'AllowNull'        => true,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field3_date'] = array(
			'ColumnName'       => '`field3_date`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 4,
			'DbType'           => 'date',
			'AllowNull'        => true,
			'DefaultValue'     => '2007-02-25',
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field4_float'] = array(
			'ColumnName'       => '`field4_float`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 5,
			'DbType'           => 'float',
			'AllowNull'        => false,
			'DefaultValue'     => 10,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field5_float'] = array(
			'ColumnName'       => '`field5_float`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 6,
			'DbType'           => 'float',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => 5,
			'NumericScale'     => 4,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field6_double'] = array(
			'ColumnName'       => '`field6_double`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 7,
			'DbType'           => 'double',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field7_datetime'] = array(
			'ColumnName'       => '`field7_datetime`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 8,
			'DbType'           => 'datetime',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field8_timestamp'] = array(
			'ColumnName'       => '`field8_timestamp`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 9,
			'DbType'           => 'timestamp',
			'AllowNull'        => true,
			'DefaultValue'     => 'CURRENT_TIMESTAMP',
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field9_time'] = array(
			'ColumnName'       => '`field9_time`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 10,
			'DbType'           => 'time',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field10_year'] = array(
			'ColumnName'       => '`field10_year`',
			'ColumnSize'       => 4,
			'ColumnIndex'      => 11,
			'DbType'           => 'year',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
		);
		$columns['field11_enum'] = array(
			'ColumnName'       => '`field11_enum`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 12,
			'DbType'           => 'enum',
			'AllowNull'        => false,
			'DefaultValue'     => 'one',
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
			'DbTypeValues'     => array('one', 'two', 'three'),
		);
		$columns['field12_SET'] = array(
			'ColumnName'       => '`field12_SET`',
			'ColumnSize'       => null,
			'ColumnIndex'      => 13,
			'DbType'           => 'set',
			'AllowNull'        => false,
			'DefaultValue'     => TDbTableColumn::UNDEFINED_VALUE,
			'NumericPrecision' => null,
			'NumericScale'     => null,
			'IsPrimaryKey'     => false,
			'IsForeignKey'     => false,
			'SequenceName'     => null,
			'AutoIncrement'    => false,
			'DbTypeValues'     => array('blue', 'red', 'green'),
		);
		$this->assertColumn($columns, $table);
		$this->assertNull($table->getSchemaName());
		$this->assertEqual('table1', $table->getTableName());
		$this->assertEqual(array('id', 'name'), $table->getPrimaryKeys());
	}
	function assertColumn($columns, $table)
	{
		foreach($columns as $id=>$asserts)
		{
			$column = $table->Columns[$id];
			foreach($asserts as $property=>$assert)
			{
				$ofAssert= var_export($assert,true);
				$value = $column->{$property};
				$ofValue = var_export($value, true);
				$this->assertEqual($value, $assert,
					"Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
			}
		}
	}
}
?>
  |