@@ -61,8 +61,8 @@ public T INSERT_INTO(String tableName) {
61
61
}
62
62
63
63
public T VALUES (String columns , String values ) {
64
- sql (). columns . add (columns );
65
- sql (). values . add (values );
64
+ INTO_COLUMNS (columns );
65
+ INTO_VALUES (values );
66
66
return getSelf ();
67
67
}
68
68
@@ -78,7 +78,10 @@ public T INTO_COLUMNS(String... columns) {
78
78
* @since 3.4.2
79
79
*/
80
80
public T INTO_VALUES (String ... values ) {
81
- sql ().values .addAll (Arrays .asList (values ));
81
+ List <String > list = sql ().valuesList .get (sql ().valuesList .size () - 1 );
82
+ for (String value : values ) {
83
+ list .add (value );
84
+ }
82
85
return getSelf ();
83
86
}
84
87
@@ -310,6 +313,16 @@ public T OFFSET(long value) {
310
313
return getSelf ();
311
314
}
312
315
316
+ /**
317
+ * used to add a new inserted row while do multi-row insert.
318
+ *
319
+ * @since 3.5.2
320
+ */
321
+ public T ADD_ROW () {
322
+ sql ().valuesList .add (new ArrayList <>());
323
+ return getSelf ();
324
+ }
325
+
313
326
private SQLStatement sql () {
314
327
return sql ;
315
328
}
@@ -360,27 +373,28 @@ public enum StatementType {
360
373
}
361
374
362
375
StatementType statementType ;
363
- List <String > sets = new ArrayList <>();
364
- List <String > select = new ArrayList <>();
365
- List <String > tables = new ArrayList <>();
366
- List <String > join = new ArrayList <>();
367
- List <String > innerJoin = new ArrayList <>();
368
- List <String > outerJoin = new ArrayList <>();
369
- List <String > leftOuterJoin = new ArrayList <>();
370
- List <String > rightOuterJoin = new ArrayList <>();
371
- List <String > where = new ArrayList <>();
372
- List <String > having = new ArrayList <>();
373
- List <String > groupBy = new ArrayList <>();
374
- List <String > orderBy = new ArrayList <>();
375
- List <String > lastList = new ArrayList <>();
376
- List <String > columns = new ArrayList <>();
377
- List <String > values = new ArrayList <>();
376
+ List <String > sets = new ArrayList <String >();
377
+ List <String > select = new ArrayList <String >();
378
+ List <String > tables = new ArrayList <String >();
379
+ List <String > join = new ArrayList <String >();
380
+ List <String > innerJoin = new ArrayList <String >();
381
+ List <String > outerJoin = new ArrayList <String >();
382
+ List <String > leftOuterJoin = new ArrayList <String >();
383
+ List <String > rightOuterJoin = new ArrayList <String >();
384
+ List <String > where = new ArrayList <String >();
385
+ List <String > having = new ArrayList <String >();
386
+ List <String > groupBy = new ArrayList <String >();
387
+ List <String > orderBy = new ArrayList <String >();
388
+ List <String > lastList = new ArrayList <String >();
389
+ List <String > columns = new ArrayList <String >();
390
+ List <List < String >> valuesList = new ArrayList <>();
378
391
boolean distinct ;
379
392
String offset ;
380
393
String limit ;
381
394
382
395
public SQLStatement () {
383
- // Prevent Synthetic Access
396
+ // Prevent Synthetic Access
397
+ valuesList .add (new ArrayList <>());
384
398
}
385
399
386
400
private void sqlClause (SafeAppendable builder , String keyword , List <String > parts , String open , String close ,
@@ -438,7 +452,9 @@ private void joins(SafeAppendable builder) {
438
452
private String insertSQL (SafeAppendable builder ) {
439
453
sqlClause (builder , "INSERT INTO" , tables , "" , "" , "" );
440
454
sqlClause (builder , "" , columns , "(" , ")" , ", " );
441
- sqlClause (builder , "VALUES" , values , "(" , ")" , ", " );
455
+ for (int i = 0 ; i < valuesList .size (); i ++) {
456
+ sqlClause (builder , i > 0 ? "," : "VALUES" , valuesList .get (i ), "(" , ")" , ", " );
457
+ }
442
458
return builder .toString ();
443
459
}
444
460
@@ -494,4 +510,4 @@ public String sql(Appendable a) {
494
510
return answer ;
495
511
}
496
512
}
497
- }
513
+ }
0 commit comments