| @@ -105,8 +105,10 @@ | ||
| 105 | 105 | * |
| 106 | 106 | * @param string $column_name The column name. |
| 107 | 107 | * @param string $type The column type. |
| 108 | 108 | * @param array $options The options. |
| 109 | + * | |
| 110 | + * @return void | |
| 109 | 111 | */ |
| 110 | 112 | public function column( $column_name, $type, $options = [] ) { |
| 111 | 113 | // If there is already a column by the same name then silently fail and continue. |
| 112 | 114 | foreach ( $this->columns as $column ) { |
| @@ -135,8 +137,10 @@ | ||
| 135 | 137 | * Shortcut to create timestamps columns (default created_at, updated_at) |
| 136 | 138 | * |
| 137 | 139 | * @param string $created_column_name Created at column name. |
| 138 | 140 | * @param string $updated_column_name Updated at column name. |
| 141 | + * | |
| 142 | + * @return void | |
| 139 | 143 | */ |
| 140 | 144 | public function timestamps( $created_column_name = 'created_at', $updated_column_name = 'updated_at' ) { |
| 141 | 145 | $this->column( $created_column_name, 'datetime' ); |
| 142 | 146 | $this->column( |
| @@ -145,9 +149,9 @@ | ||
| 145 | 149 | [ |
| 146 | 150 | 'null' => false, |
| 147 | 151 | 'default' => 'CURRENT_TIMESTAMP', |
| 148 | 152 | 'extra' => 'ON UPDATE CURRENT_TIMESTAMP', |
| 149 | - ] | |
| 153 | + ], | |
| 150 | 154 | ); |
| 151 | 155 | } |
| 152 | 156 | |
| 153 | 157 | /** |
| @@ -175,9 +179,9 @@ | ||
| 175 | 179 | * @param bool $wants_sql Whether or not to return SQL or execute the query. Defaults to false. |
| 176 | 180 | * |
| 177 | 181 | * @return bool|string |
| 178 | 182 | * |
| 179 | - * @throws Exception If the table definition has not been intialized. | |
| 183 | + * @throws Exception If the table definition has not been initialized. | |
| 180 | 184 | */ |
| 181 | 185 | public function finish( $wants_sql = false ) { |
| 182 | 186 | if ( ! $this->initialized ) { |
| 183 | 187 | throw new Exception( \sprintf( "Table Definition: '%s' has not been initialized", $this->name ) ); |
| @@ -185,15 +189,13 @@ | ||
| 185 | 189 | $opt_str = ''; |
| 186 | 190 | if ( \is_array( $this->options ) && \array_key_exists( 'options', $this->options ) ) { |
| 187 | 191 | $opt_str = $this->options['options']; |
| 188 | 192 | } |
| 193 | + elseif ( isset( $this->adapter->db_info['charset'] ) ) { | |
| 194 | + $opt_str = ' DEFAULT CHARSET=' . $this->adapter->db_info['charset']; | |
| 195 | + } | |
| 189 | 196 | else { |
| 190 | - if ( isset( $this->adapter->db_info['charset'] ) ) { | |
| 191 | - $opt_str = ' DEFAULT CHARSET=' . $this->adapter->db_info['charset']; | |
| 192 | - } | |
| 193 | - else { | |
| 194 | - $opt_str = ' DEFAULT CHARSET=utf8'; | |
| 195 | - } | |
| 197 | + $opt_str = ' DEFAULT CHARSET=utf8'; | |
| 196 | 198 | } |
| 197 | 199 | $close_sql = \sprintf( ') %s;', $opt_str ); |
| 198 | 200 | $create_table_sql = $this->sql; |
| 199 | 201 | if ( $this->auto_generate_id === true ) { |
| @@ -205,9 +207,9 @@ | ||
| 205 | 207 | [ |
| 206 | 208 | 'unsigned' => true, |
| 207 | 209 | 'null' => false, |
| 208 | 210 | 'auto_increment' => true, |
| 209 | - ] | |
| 211 | + ], | |
| 210 | 212 | ); |
| 211 | 213 | $create_table_sql .= $primary_id->to_sql() . ",\n"; |
| 212 | 214 | } |
| 213 | 215 | $create_table_sql .= $this->columns_to_str(); |
| @@ -223,9 +225,8 @@ | ||
| 223 | 225 | * |
| 224 | 226 | * @return string The SQL. |
| 225 | 227 | */ |
| 226 | 228 | private function columns_to_str() { |
| 227 | - $str = ''; | |
| 228 | 229 | $fields = []; |
| 229 | 230 | $len = \count( $this->columns ); |
| 230 | 231 | for ( $i = 0; $i < $len; $i++ ) { |
| 231 | 232 | $c = $this->columns[ $i ]; |
| @@ -238,8 +239,10 @@ | ||
| 238 | 239 | * Init create sql statement. |
| 239 | 240 | * |
| 240 | 241 | * @param string $name The name. |
| 241 | 242 | * @param array $options The options. |
| 243 | + * | |
| 244 | + * @return void | |
| 242 | 245 | */ |
| 243 | 246 | private function init_sql( $name, $options ) { |
| 244 | 247 | // Are we forcing table creation? If so, drop it first. |
| 245 | 248 | if ( \array_key_exists( 'force', $options ) && $options['force'] === true ) { |