@@ -396,8 +396,8 @@ function createTable ($name, $data) {
396396}
397397unset ($ cnt );
398398
399- $ data = $ db ->get ('users ' );
400- if (count ($ data ) != 3 ) {
399+ $ users = $ db ->get ('users ' );
400+ if (count ($ users ) != 3 ) {
401401 echo "copy with subquery data count failed " ;
402402 exit ;
403403}
@@ -444,6 +444,47 @@ function createTable ($name, $data) {
444444 exit ;
445445}
446446
447+ $ expectedIDs = [
448+ 'users ' => [5 , 6 , 7 ],
449+ 'products ' => [6 ,7 ,8 ,9 ,10 ],
450+ ];
451+
452+ // multi-insert test with autoincrement
453+ foreach ($ data as $ name => $ datas ) {
454+
455+ // remove previous entries to ensure avoiding PRIMARY-KEY collisions here
456+ $ db ->delete ($ name );
457+
458+ // actual insertion test
459+ $ ids = $ db ->insertMulti ($ name , $ datas );
460+
461+ // check results
462+ if (!$ ids ) {
463+ echo "failed to multi-insert: " .$ db ->getLastQuery () ."\n" . $ db ->getLastError ();
464+ exit ;
465+ } elseif ($ ids !== $ expectedIDs [$ name ]) {
466+ pretty_print ($ ids );
467+ echo "multi-insert succeeded, but unexpected id's: " .$ db ->getLastQuery () ."\n" . $ db ->getLastError ();
468+ exit ;
469+ }
470+ }
471+
472+ // skip last user here, since it has other keys than the others
473+ unset($ data ['users ' ][2 ]);
474+
475+ // multi-insert test with autoincrement and overriding column-names
476+ foreach ($ data as $ name => $ datas ) {
477+
478+ // remove previous entries to ensure avoiding PRIMARY-KEY collisions here
479+ $ db ->delete ($ name );
480+
481+ // actual insertion test
482+ if (!$ db ->insertMulti ($ name , $ datas , array_keys ($ datas [0 ]))) {
483+ echo "failed to multi-insert: " .$ db ->getLastQuery () ."\n" . $ db ->getLastError ();
484+ exit ;
485+ }
486+ }
487+
447488///
448489//TODO: insert test
449490$ db ->delete ("users " );
0 commit comments