@@ -88,7 +88,7 @@ class DboSqlite extends DboSource {
88
88
'primary_key ' => array ('name ' => 'integer primary key ' ),
89
89
'string ' => array ('name ' => 'varchar ' , 'limit ' => '255 ' ),
90
90
'text ' => array ('name ' => 'text ' ),
91
- 'integer ' => array ('name ' => 'integer ' , 'limit ' => null , 'formatter ' => 'intval ' ),
91
+ 'integer ' => array ('name ' => 'integer ' , 'limit ' => 11 , 'formatter ' => 'intval ' ),
92
92
'float ' => array ('name ' => 'float ' , 'formatter ' => 'floatval ' ),
93
93
'datetime ' => array ('name ' => 'datetime ' , 'format ' => 'Y-m-d H:i:s ' , 'formatter ' => 'date ' ),
94
94
'timestamp ' => array ('name ' => 'timestamp ' , 'format ' => 'Y-m-d H:i:s ' , 'formatter ' => 'date ' ),
@@ -190,18 +190,19 @@ function describe(&$model) {
190
190
191
191
foreach ($ result as $ column ) {
192
192
$ fields [$ column [0 ]['name ' ]] = array (
193
- 'type ' => $ this ->column ($ column [0 ]['type ' ]),
194
- 'null ' => !$ column [0 ]['notnull ' ],
195
- 'default ' => $ column [0 ]['dflt_value ' ],
196
- 'length ' => $ this ->length ($ column [0 ]['type ' ])
193
+ 'type ' => $ this ->column ($ column [0 ]['type ' ]),
194
+ 'null ' => !$ column [0 ]['notnull ' ],
195
+ 'default ' => $ column [0 ]['dflt_value ' ],
196
+ 'length ' => $ this ->length ($ column [0 ]['type ' ])
197
197
);
198
198
if ($ column [0 ]['pk ' ] == 1 ) {
199
+ $ colLength = $ this ->length ($ column [0 ]['type ' ]);
199
200
$ fields [$ column [0 ]['name ' ]] = array (
200
- 'type ' => $ fields [$ column [0 ]['name ' ]]['type ' ],
201
- 'null ' => false ,
202
- 'default ' => $ column [0 ]['dflt_value ' ],
203
- 'key ' => $ this ->index ['PRI ' ],
204
- 'length ' => 11
201
+ 'type ' => $ fields [$ column [0 ]['name ' ]]['type ' ],
202
+ 'null ' => false ,
203
+ 'default ' => $ column [0 ]['dflt_value ' ],
204
+ 'key ' => $ this ->index ['PRI ' ],
205
+ 'length ' => ( $ colLength != null ) ? $ colLength : 11
205
206
);
206
207
}
207
208
}
@@ -449,34 +450,34 @@ function buildColumn($column) {
449
450
}
450
451
451
452
$ real = $ this ->columns [$ type ];
452
- if (isset ($ column ['key ' ]) && $ column ['key ' ] == 'primary ' ) {
453
- $ out = $ this ->name ($ name ) . ' ' . $ this ->columns ['primary_key ' ]['name ' ];
454
- } else {
455
- $ out = $ this ->name ($ name ) . ' ' . $ real ['name ' ];
456
-
457
- if (isset ($ real ['limit ' ]) || isset ($ real ['length ' ]) || isset ($ column ['limit ' ]) || isset ($ column ['length ' ])) {
458
- if (isset ($ column ['length ' ])) {
459
- $ length = $ column ['length ' ];
460
- } elseif (isset ($ column ['limit ' ])) {
461
- $ length = $ column ['limit ' ];
462
- } elseif (isset ($ real ['length ' ])) {
463
- $ length = $ real ['length ' ];
464
- } else {
465
- $ length = $ real ['limit ' ];
466
- }
467
- $ out .= '( ' . $ length . ') ' ;
468
- }
469
- if (isset ($ column ['key ' ]) && $ column ['key ' ] == 'primary ' ) {
470
- $ out .= ' NOT NULL ' ;
471
- } elseif (isset ($ column ['default ' ]) && isset ($ column ['null ' ]) && $ column ['null ' ] == false ) {
472
- $ out .= ' DEFAULT ' . $ this ->value ($ column ['default ' ], $ type ) . ' NOT NULL ' ;
473
- } elseif (isset ($ column ['default ' ])) {
474
- $ out .= ' DEFAULT ' . $ this ->value ($ column ['default ' ], $ type );
475
- } elseif (isset ($ column ['null ' ]) && $ column ['null ' ] == true ) {
476
- $ out .= ' DEFAULT NULL ' ;
477
- } elseif (isset ($ column ['null ' ]) && $ column ['null ' ] == false ) {
478
- $ out .= ' NOT NULL ' ;
453
+ $ out = $ this ->name ($ name ) . ' ' . $ real ['name ' ];
454
+ if (isset ($ column ['key ' ]) && $ column ['key ' ] == 'primary ' && $ type == 'integer ' ) {
455
+ return $ this ->name ($ name ) . ' ' . $ this ->columns ['primary_key ' ]['name ' ];
456
+ }
457
+ if (isset ($ real ['limit ' ]) || isset ($ real ['length ' ]) || isset ($ column ['limit ' ]) || isset ($ column ['length ' ])) {
458
+ if (isset ($ column ['length ' ])) {
459
+ $ length = $ column ['length ' ];
460
+ } elseif (isset ($ column ['limit ' ])) {
461
+ $ length = $ column ['limit ' ];
462
+ } elseif (isset ($ real ['length ' ])) {
463
+ $ length = $ real ['length ' ];
464
+ } else {
465
+ $ length = $ real ['limit ' ];
479
466
}
467
+ $ out .= '( ' . $ length . ') ' ;
468
+ }
469
+ if (isset ($ column ['key ' ]) && $ column ['key ' ] == 'primary ' && $ type == 'integer ' ) {
470
+ $ out .= ' ' . $ this ->columns ['primary_key ' ]['name ' ];
471
+ } elseif (isset ($ column ['key ' ]) && $ column ['key ' ] == 'primary ' ) {
472
+ $ out .= ' NOT NULL ' ;
473
+ } elseif (isset ($ column ['default ' ]) && isset ($ column ['null ' ]) && $ column ['null ' ] == false ) {
474
+ $ out .= ' DEFAULT ' . $ this ->value ($ column ['default ' ], $ type ) . ' NOT NULL ' ;
475
+ } elseif (isset ($ column ['default ' ])) {
476
+ $ out .= ' DEFAULT ' . $ this ->value ($ column ['default ' ], $ type );
477
+ } elseif (isset ($ column ['null ' ]) && $ column ['null ' ] == true ) {
478
+ $ out .= ' DEFAULT NULL ' ;
479
+ } elseif (isset ($ column ['null ' ]) && $ column ['null ' ] == false ) {
480
+ $ out .= ' NOT NULL ' ;
480
481
}
481
482
return $ out ;
482
483
}
0 commit comments