File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1616
1717/**
1818 * Class Query
19+ *
1920 * @package IronBound\DB
2021 */
2122class Simple_Query {
@@ -34,7 +35,7 @@ class Simple_Query {
3435 * Constructor.
3536 *
3637 * @param \wpdb $wpdb
37- * @param Table $table
38+ * @param Table $table
3839 */
3940 public function __construct ( \wpdb $ wpdb , Table $ table ) {
4041 $ this ->wpdb = $ wpdb ;
@@ -211,6 +212,20 @@ public function insert( $data ) {
211212 $ data_keys = array_keys ( $ data );
212213 $ column_formats = array_merge ( array_flip ( $ data_keys ), $ column_formats );
213214
215+ $ null_columns = array ();
216+
217+ foreach ( $ data as $ col => $ val ) {
218+
219+ if ( $ val == null ) {
220+ $ null_columns [] = $ col ;
221+ }
222+ }
223+
224+ foreach ( $ null_columns as $ null_column ) {
225+ unset( $ data [ $ null_column ] );
226+ unset( $ column_formats [ $ null_column ] );
227+ }
228+
214229 $ prev = $ this ->wpdb ->show_errors ( false );
215230 $ this ->wpdb ->insert ( $ this ->table ->get_table_name ( $ this ->wpdb ), $ data , $ column_formats );
216231 $ this ->wpdb ->show_errors ( $ prev );
@@ -338,6 +353,10 @@ public function escape_value( $column, $value ) {
338353 throw new Exception ( "Invalid database column. " );
339354 }
340355
356+ if ( empty ( $ value ) ) {
357+ return '' ;
358+ }
359+
341360 $ column_format = $ columns [ $ column ];
342361
343362 if ( $ value [0 ] == '% ' ) {
You can’t perform that action at this time.
0 commit comments