@@ -47,7 +47,7 @@ public class DuckDBPreparedStatement implements PreparedStatement {
47
47
volatile boolean closeOnCompletion = false ;
48
48
49
49
private DuckDBResultSet selectResult = null ;
50
- private int updateResult = 0 ;
50
+ private long updateResult = 0 ;
51
51
52
52
private boolean returnsChangedRows = false ;
53
53
private boolean returnsNothing = false ;
@@ -188,7 +188,7 @@ private boolean execute(boolean startTransaction) throws SQLException {
188
188
189
189
if (returnsChangedRows ) {
190
190
if (selectResult .next ()) {
191
- updateResult = selectResult .getInt (1 );
191
+ updateResult = selectResult .getLong (1 );
192
192
}
193
193
selectResult .close ();
194
194
}
@@ -208,6 +208,12 @@ public ResultSet executeQuery() throws SQLException {
208
208
209
209
@ Override
210
210
public int executeUpdate () throws SQLException {
211
+ long res = executeLargeUpdate ();
212
+ return intFromLong (res );
213
+ }
214
+
215
+ @ Override
216
+ public long executeLargeUpdate () throws SQLException {
211
217
requireNonBatch ();
212
218
execute ();
213
219
if (!(returnsChangedRows || returnsNothing )) {
@@ -232,8 +238,14 @@ public ResultSet executeQuery(String sql) throws SQLException {
232
238
233
239
@ Override
234
240
public int executeUpdate (String sql ) throws SQLException {
241
+ long res = executeLargeUpdate (sql );
242
+ return intFromLong (res );
243
+ }
244
+
245
+ @ Override
246
+ public long executeLargeUpdate (String sql ) throws SQLException {
235
247
prepare (sql );
236
- return executeUpdate ();
248
+ return executeLargeUpdate ();
237
249
}
238
250
239
251
@ Override
@@ -377,12 +389,22 @@ public void setMaxFieldSize(int max) throws SQLException {
377
389
378
390
@ Override
379
391
public int getMaxRows () throws SQLException {
392
+ return (int ) getLargeMaxRows ();
393
+ }
394
+
395
+ @ Override
396
+ public void setMaxRows (int max ) throws SQLException {
397
+ setLargeMaxRows (max );
398
+ }
399
+
400
+ @ Override
401
+ public long getLargeMaxRows () throws SQLException {
380
402
checkOpen ();
381
403
return 0 ;
382
404
}
383
405
384
406
@ Override
385
- public void setMaxRows ( int max ) throws SQLException {
407
+ public void setLargeMaxRows ( long max ) throws SQLException {
386
408
checkOpen ();
387
409
}
388
410
@@ -450,7 +472,7 @@ public ResultSet getResultSet() throws SQLException {
450
472
return to_return ;
451
473
}
452
474
453
- private Integer getUpdateCountInternal () throws SQLException {
475
+ private long getUpdateCountInternal () throws SQLException {
454
476
if (isClosed ()) {
455
477
throw new SQLException ("Statement was closed" );
456
478
}
@@ -465,11 +487,17 @@ private Integer getUpdateCountInternal() throws SQLException {
465
487
}
466
488
467
489
@ Override
468
- public int getUpdateCount () throws SQLException {
490
+ public long getLargeUpdateCount () throws SQLException {
469
491
// getUpdateCount can only be called once per result
470
- int to_return = getUpdateCountInternal ();
492
+ long res = getUpdateCountInternal ();
471
493
updateResult = -1 ;
472
- return to_return ;
494
+ return res ;
495
+ }
496
+
497
+ @ Override
498
+ public int getUpdateCount () throws SQLException {
499
+ long res = getLargeUpdateCount ();
500
+ return intFromLong (res );
473
501
}
474
502
475
503
@ Override
@@ -534,6 +562,12 @@ public void clearBatch() throws SQLException {
534
562
535
563
@ Override
536
564
public int [] executeBatch () throws SQLException {
565
+ long [] res = executeLargeBatch ();
566
+ return intArrayFromLong (res );
567
+ }
568
+
569
+ @ Override
570
+ public long [] executeLargeBatch () throws SQLException {
537
571
checkOpen ();
538
572
try {
539
573
if (this .isPreparedStatement ) {
@@ -546,26 +580,26 @@ public int[] executeBatch() throws SQLException {
546
580
}
547
581
}
548
582
549
- private int [] executeBatchedPreparedStatement () throws SQLException {
550
- int [] updateCounts = new int [this .batchedParams .size ()];
583
+ private long [] executeBatchedPreparedStatement () throws SQLException {
584
+ long [] updateCounts = new long [this .batchedParams .size ()];
551
585
552
586
startTransaction ();
553
587
for (int i = 0 ; i < this .batchedParams .size (); i ++) {
554
588
params = this .batchedParams .get (i );
555
589
execute (false );
556
- updateCounts [i ] = getUpdateCount ();
590
+ updateCounts [i ] = getUpdateCountInternal ();
557
591
}
558
592
return updateCounts ;
559
593
}
560
594
561
- private int [] executeBatchedStatements () throws SQLException {
562
- int [] updateCounts = new int [this .batchedStatements .size ()];
595
+ private long [] executeBatchedStatements () throws SQLException {
596
+ long [] updateCounts = new long [this .batchedStatements .size ()];
563
597
564
598
startTransaction ();
565
599
for (int i = 0 ; i < this .batchedStatements .size (); i ++) {
566
600
prepare (this .batchedStatements .get (i ));
567
601
execute (false );
568
- updateCounts [i ] = getUpdateCount ();
602
+ updateCounts [i ] = getUpdateCountInternal ();
569
603
}
570
604
return updateCounts ;
571
605
}
@@ -590,22 +624,40 @@ public ResultSet getGeneratedKeys() throws SQLException {
590
624
591
625
@ Override
592
626
public int executeUpdate (String sql , int autoGeneratedKeys ) throws SQLException {
627
+ long res = executeLargeUpdate (sql , autoGeneratedKeys );
628
+ return intFromLong (res );
629
+ }
630
+
631
+ @ Override
632
+ public long executeLargeUpdate (String sql , int autoGeneratedKeys ) throws SQLException {
593
633
if (NO_GENERATED_KEYS == autoGeneratedKeys ) {
594
- return executeUpdate (sql );
634
+ return executeLargeUpdate (sql );
595
635
}
596
636
throw new SQLFeatureNotSupportedException ("executeUpdate(String sql, int autoGeneratedKeys)" );
597
637
}
598
638
599
639
@ Override
600
640
public int executeUpdate (String sql , int [] columnIndexes ) throws SQLException {
641
+ long res = executeLargeUpdate (sql , columnIndexes );
642
+ return intFromLong (res );
643
+ }
644
+
645
+ @ Override
646
+ public long executeLargeUpdate (String sql , int [] columnIndexes ) throws SQLException {
601
647
if (columnIndexes == null || columnIndexes .length == 0 ) {
602
- return executeUpdate (sql );
648
+ return executeLargeUpdate (sql );
603
649
}
604
650
throw new SQLFeatureNotSupportedException ("executeUpdate(String sql, int[] columnIndexes)" );
605
651
}
606
652
607
653
@ Override
608
654
public int executeUpdate (String sql , String [] columnNames ) throws SQLException {
655
+ long res = executeLargeUpdate (sql , columnNames );
656
+ return intFromLong (res );
657
+ }
658
+
659
+ @ Override
660
+ public long executeLargeUpdate (String sql , String [] columnNames ) throws SQLException {
609
661
if (columnNames == null || columnNames .length == 0 ) {
610
662
return executeUpdate (sql );
611
663
}
@@ -1085,4 +1137,20 @@ private void setCharacterReaderInternal(int parameterIndex, Reader reader, long
1085
1137
String str = readToString (wrappedReader );
1086
1138
setObject (parameterIndex , str );
1087
1139
}
1140
+
1141
+ private int intFromLong (long val ) {
1142
+ if (val <= Integer .MAX_VALUE ) {
1143
+ return (int ) val ;
1144
+ } else {
1145
+ return Integer .MAX_VALUE ;
1146
+ }
1147
+ }
1148
+
1149
+ private int [] intArrayFromLong (long [] arr ) {
1150
+ int [] res = new int [arr .length ];
1151
+ for (int i = 0 ; i < arr .length ; i ++) {
1152
+ res [i ] = intFromLong (arr [i ]);
1153
+ }
1154
+ return res ;
1155
+ }
1088
1156
}
0 commit comments