@@ -5605,56 +5605,43 @@ private function get_sqlite_create_table_statement(
56055605 ksort ( $ constraint );
56065606 $ info = $ constraint [1 ];
56075607
5608+ $ column_list = array_map (
5609+ function ( $ column ) {
5610+ $ fragment = $ this ->quote_sqlite_identifier ( $ column ['COLUMN_NAME ' ] );
5611+ if ( 'D ' === $ column ['COLLATION ' ] ) {
5612+ $ fragment .= ' DESC ' ;
5613+ }
5614+ return $ fragment ;
5615+ },
5616+ $ constraint
5617+ );
5618+
56085619 if ( 'PRIMARY ' === $ info ['INDEX_NAME ' ] ) {
56095620 if ( $ has_autoincrement ) {
5610- if ( count ( $ constraint ) > 1 ) {
5611- throw $ this ->new_driver_exception (
5612- 'Cannot combine AUTOINCREMENT and multiple primary keys in SQLite '
5613- );
5621+ if ( $ has_autoincrement ) {
5622+ if ( count ( $ constraint ) > 1 ) {
5623+ throw $ this ->new_driver_exception (
5624+ 'Cannot combine AUTOINCREMENT and multiple primary keys in SQLite '
5625+ );
5626+ }
56145627 }
56155628 continue ;
56165629 }
5617- $ query = ' PRIMARY KEY ( ' ;
5618- $ query .= implode (
5619- ', ' ,
5620- array_map (
5621- function ( $ column ) {
5622- return $ this ->quote_sqlite_identifier ( $ column ['COLUMN_NAME ' ] );
5623- },
5624- $ constraint
5625- )
5626- );
5627- $ query .= ') ' ;
5628- $ rows [] = $ query ;
5630+ $ rows [] = sprintf ( ' PRIMARY KEY (%s) ' , implode ( ', ' , $ column_list ) );
56295631 } else {
56305632 $ is_unique = '0 ' === $ info ['NON_UNIQUE ' ];
56315633
56325634 // Prefix the original index name with the table name.
56335635 // This is to avoid conflicting index names in SQLite.
56345636 $ sqlite_index_name = $ this ->get_sqlite_index_name ( $ table_name , $ info ['INDEX_NAME ' ] );
56355637
5636- $ query = sprintf (
5637- 'CREATE %sINDEX %s ON %s ( ' ,
5638+ $ create_index_queries [] = sprintf (
5639+ 'CREATE %sINDEX %s ON %s (%s) ' ,
56385640 $ is_unique ? 'UNIQUE ' : '' ,
56395641 $ this ->quote_sqlite_identifier ( $ sqlite_index_name ),
5640- $ this ->quote_sqlite_identifier ( $ table_name )
5641- );
5642- $ query .= implode (
5643- ', ' ,
5644- array_map (
5645- function ( $ column ) {
5646- $ fragment = $ this ->quote_sqlite_identifier ( $ column ['COLUMN_NAME ' ] );
5647- if ( 'D ' === $ column ['COLLATION ' ] ) {
5648- $ fragment .= ' DESC ' ;
5649- }
5650- return $ fragment ;
5651- },
5652- $ constraint
5653- )
5642+ $ this ->quote_sqlite_identifier ( $ table_name ),
5643+ implode ( ', ' , $ column_list )
56545644 );
5655- $ query .= ') ' ;
5656-
5657- $ create_index_queries [] = $ query ;
56585645 }
56595646 }
56605647
0 commit comments