-
Notifications
You must be signed in to change notification settings - Fork 154
/
SnowflakePreparedStatementV1.java
950 lines (817 loc) · 28.7 KB
/
SnowflakePreparedStatementV1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
/*
* Copyright (c) 2012-2018 Snowflake Computing Inc. All rights reserved.
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.snowflake.client.jdbc;
import net.snowflake.client.core.ParameterBindingDTO;
import net.snowflake.client.core.ResultUtil;
import net.snowflake.client.core.SFException;
import net.snowflake.client.core.SFStatementMetaData;
import net.snowflake.common.core.SFBinary;
import net.snowflake.common.core.SqlState;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
/**
*
* @author jhuang
*/
final class SnowflakePreparedStatementV1 extends SnowflakeStatementV1
implements PreparedStatement
{
static final SFLogger logger = SFLoggerFactory.getLogger(
SnowflakePreparedStatementV1.class);
private final String sql;
/** statement and result metadata from describe phase */
private SFStatementMetaData statementMetaData;
/**
* map of bind name to bind values for single query execution
*
* Currently, bind name is just value index
*/
private Map<String, ParameterBindingDTO> parameterBindings = new HashMap<>();
/**
* map of bind values for batch query executions
*
*/
private Map<String, ParameterBindingDTO> batchParameterBindings =
new HashMap<>();
/**
* Counter for batch size if we are executing a statement with array bind
* supported
*/
private int batchSize = 0;
/** Error code returned when describing a statement that is binding table name*/
private final Integer ERROR_CODE_TABLE_BIND_VARIABLE_NOT_SET = 2128;
/** Error code when preparing statement with binding object names */
private final Integer ERROR_CODE_OBJECT_BIND_NOT_SET = 2129;
/** Error code returned when describing a ddl command */
private final Integer ERROR_CODE_STATEMENT_CANNOT_BE_PREPARED = 7;
/**
* A hash set that contains the error code that will not lead to exception
* in describe mode
*/
private final Set<Integer> errorCodesIgnoredInDescribeMode
= new HashSet<>(Arrays.asList(new Integer[]
{ERROR_CODE_TABLE_BIND_VARIABLE_NOT_SET,
ERROR_CODE_STATEMENT_CANNOT_BE_PREPARED,
ERROR_CODE_OBJECT_BIND_NOT_SET}));
SnowflakePreparedStatementV1(SnowflakeConnectionV1 connection,
String sql) throws SQLException
{
super(connection);
this.sql = sql;
try
{
this.statementMetaData = sfStatement.describe(sql);
}
catch(SFException e)
{
throw new SnowflakeSQLException(e);
}
catch(SnowflakeSQLException e)
{
if (!errorCodesIgnoredInDescribeMode.contains(e.getErrorCode()))
{
throw e;
}
else
{
statementMetaData = SFStatementMetaData.emptyMetaData();
}
}
}
@Override
public ResultSet executeQuery() throws SQLException
{
logger.debug("executeQuery() throws SQLException");
return executeQueryInternal(sql, parameterBindings);
}
@Override
public int executeUpdate() throws SQLException
{
logger.debug( "executeUpdate() throws SQLException");
return executeUpdateInternal(sql, parameterBindings);
}
@Override
public void setNull(int parameterIndex, int sqlType) throws SQLException
{
logger.debug(
"setNull(int parameterIndex, int sqlType) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(sqlType), null);
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setBoolean(int parameterIndex, boolean x) throws SQLException
{
logger.debug(
"setBoolean(int parameterIndex, boolean x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.BOOLEAN), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setByte(int parameterIndex, byte x) throws SQLException
{
throw new UnsupportedOperationException(
"setByte(int parameterIndex, byte x) Not supported yet.");
}
@Override
public void setShort(int parameterIndex, short x) throws SQLException
{
logger.debug(
"setShort(int parameterIndex, short x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(SnowflakeUtil
.javaTypeToSFTypeString(Types.SMALLINT), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setInt(int parameterIndex, int x) throws SQLException
{
logger.debug(
"setInt(int parameterIndex, int x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(SnowflakeUtil
.javaTypeToSFTypeString(Types.INTEGER), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setLong(int parameterIndex, long x) throws SQLException
{
logger.debug(
"setLong(int parameterIndex, long x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.BIGINT), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setFloat(int parameterIndex, float x) throws SQLException
{
logger.debug(
"setFloat(int parameterIndex, float x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.FLOAT), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setDouble(int parameterIndex, double x) throws SQLException
{
logger.debug(
"setDouble(int parameterIndex, double x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.DOUBLE), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
logger.debug(
"setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException");
if (x == null)
{
setNull(parameterIndex, Types.DECIMAL);
}
else
{
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.DECIMAL), String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
}
@Override
public void setString(int parameterIndex, String x) throws SQLException
{
logger.debug(
"setString(int parameterIndex, String x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.VARCHAR), x);
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setBytes(int parameterIndex, byte[] x) throws SQLException
{
logger.debug(
"setBytes(int parameterIndex, byte[] x) throws SQLException");
ParameterBindingDTO binding = new ParameterBindingDTO(SnowflakeUtil
.javaTypeToSFTypeString(Types.BINARY), new SFBinary(x).toHex());
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setDate(int parameterIndex, Date x) throws SQLException
{
logger.debug(
"setDate(int parameterIndex, Date x) throws SQLException");
if (x == null)
{
setNull(parameterIndex, Types.DATE);
}
else
{
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.DATE),
String.valueOf(x.getTime() +
TimeZone.getDefault().getOffset(x.getTime())-
ResultUtil.msDiffJulianToGregorian(x)));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
}
@Override
public void setTime(int parameterIndex, Time x) throws SQLException
{
logger.debug(
"setTime(int parameterIndex, Time x) throws SQLException");
if (x == null)
{
setNull(parameterIndex, Types.TIME);
}
else
{
// Convert to nanoseconds since midnight using the input time mod 24 hours.
final long MS_IN_DAY = 86400 * 1000;
long msSinceEpoch = x.getTime();
// Use % + % instead of just % to get the nonnegative remainder.
// TODO(mkember): Change to use Math.floorMod when Client is on Java 8.
long msSinceMidnight = (msSinceEpoch % MS_IN_DAY + MS_IN_DAY) % MS_IN_DAY;
long nanosSinceMidnight = msSinceMidnight * 1000 * 1000;
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.TIME),
String.valueOf(nanosSinceMidnight));
parameterBindings.put(String.valueOf(parameterIndex), binding);
sfStatement.setHasUnsupportedStageBind(true);
}
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
{
logger.debug(
"setTimestamp(int parameterIndex, Timestamp x) throws SQLException");
// convert the timestamp from being in local time zone to be in UTC timezone
String value = x == null ? null :
String.valueOf(
BigDecimal.valueOf((x.getTime() - ResultUtil.msDiffJulianToGregorian(x))/1000).
scaleByPowerOfTen(9).add(BigDecimal.valueOf(x.getNanos())));
SnowflakeType sfType = SnowflakeUtil.javaTypeToSFType(Types.TIMESTAMP);
if (sfType == SnowflakeType.TIMESTAMP)
{
sfType = connection.getSfSession().getTimestampMappedType();
}
ParameterBindingDTO binding = new ParameterBindingDTO(sfType.name(), value);
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
throw new UnsupportedOperationException(
"setAsciiStream(int parameterIndex, InputStream x, int length) Not supported yet.");
}
@Override
@Deprecated
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
throw new UnsupportedOperationException(
"setUnicodeStream(int parameterIndex, InputStream x, int length) Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
throw new UnsupportedOperationException(
"setBinaryStream(int parameterIndex, InputStream x, int length) Not supported yet.");
}
@Override
public void clearParameters() throws SQLException
{
parameterBindings.clear();
if (batchParameterBindings.isEmpty())
{
sfStatement.setHasUnsupportedStageBind(false);
}
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException
{
logger.debug(
"setObject(int parameterIndex, Object x, int targetSqlType)");
if (x == null)
setNull(parameterIndex, targetSqlType);
else if (targetSqlType == Types.DATE)
setDate(parameterIndex, (Date)x);
else if (targetSqlType == Types.TIME)
setTime(parameterIndex, (Time)x);
else if (targetSqlType == Types.TIMESTAMP)
setTimestamp(parameterIndex, (Timestamp)x);
else
{
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(targetSqlType),
String.valueOf(x));
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
}
@Override
public void setObject(int parameterIndex, Object x) throws SQLException
{
if (x == null)
setNull(parameterIndex, Types.NULL);
else if (x instanceof String)
setString(parameterIndex, (String) x);
else if (x instanceof BigDecimal)
setBigDecimal(parameterIndex, (BigDecimal) x);
else if (x instanceof Short)
setShort(parameterIndex, ((Short) x).shortValue());
else if (x instanceof Integer)
setInt(parameterIndex, ((Integer) x).intValue());
else if (x instanceof Long)
setLong(parameterIndex, ((Long) x).longValue());
else if (x instanceof Float)
setFloat(parameterIndex, ((Float) x).floatValue());
else if (x instanceof Double)
setDouble(parameterIndex, ((Double) x).doubleValue());
else if (x instanceof Date)
setDate(parameterIndex, (Date)x);
else if (x instanceof Time)
setTime(parameterIndex, (Time)x);
else if (x instanceof Timestamp)
setTimestamp(parameterIndex, (Timestamp)x);
else
{
throw new SnowflakeSQLException(SqlState.FEATURE_NOT_SUPPORTED,
ErrorCode.DATA_TYPE_NOT_SUPPORTED
.getMessageCode(),
"Object type: " + x.getClass());
}
}
@Override
public boolean execute() throws SQLException
{
logger.debug( "execute: {}", sql);
return executeInternal(sql, parameterBindings);
}
@Override
public void addBatch() throws SQLException
{
logger.debug( "addBatch() throws SQLException");
if (isClosed())
{
throw new SnowflakeSQLException(ErrorCode.STATEMENT_CLOSED);
}
if (statementMetaData.isArrayBindSupported())
{
for(Map.Entry<String, ParameterBindingDTO> binding :
parameterBindings.entrySet())
{
// get the entry for the bind variable in the batch binding map
ParameterBindingDTO bindingValueAndType =
batchParameterBindings.get(binding.getKey());
List<String> values;
// create binding value and type for the first time
if (bindingValueAndType == null)
{
// create the value list
values = new ArrayList<String>();
bindingValueAndType = new ParameterBindingDTO(
binding.getValue().getType(), values);
// put the new map into the batch
batchParameterBindings.put(binding.getKey(),
bindingValueAndType);
}
else
{
// make sure type matches except for null values
String prevType = bindingValueAndType.getType();
String newType = binding.getValue().getType();
// if previous type is null, replace it with new type
if (SnowflakeType.ANY.name().equalsIgnoreCase(prevType) &&
!SnowflakeType.ANY.name().equalsIgnoreCase(newType))
{
bindingValueAndType.setType(newType);
}
else if (binding.getValue().getValue() != null &&
!prevType.equalsIgnoreCase(newType))
{
throw new SnowflakeSQLException(SqlState.FEATURE_NOT_SUPPORTED,
ErrorCode.ARRAY_BIND_MIXED_TYPES_NOT_SUPPORTED.getMessageCode(),
SnowflakeType.getJavaType(SnowflakeType.fromString(prevType)).name(),
SnowflakeType.getJavaType(SnowflakeType.fromString(newType)).name());
}
// found the existing map so just get the value list
values = (List<String>) bindingValueAndType.getValue();
}
// add the value to the list of values in batch binding map
values.add((String)binding.getValue().getValue());
}
batchSize++;
}
else
{
batch.add(new BatchEntry(this.sql, parameterBindings));
parameterBindings = new HashMap<>();
}
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException
{
throw new UnsupportedOperationException(
"setCharacterStream(int parameterIndex, Reader reader, int length) Not supported yet.");
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException
{
throw new UnsupportedOperationException(
"setRef(int parameterIndex, Ref x) Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException
{
throw new UnsupportedOperationException(
"setBlob(int parameterIndex, Blob x) Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException
{
throw new UnsupportedOperationException(
"setClob(int parameterIndex, Clob x) Not supported yet.");
}
@Override
public void setArray(int parameterIndex, Array x) throws SQLException
{
throw new UnsupportedOperationException(
"setArray(int parameterIndex, Array x) Not supported yet.");
}
@Override
public ResultSetMetaData getMetaData() throws SQLException
{
logger.debug( "getMetaData() throws SQLException");
return new SnowflakeResultSetMetaDataV1(
this.statementMetaData.getResultSetMetaData());
}
@Override
public void setDate(int parameterIndex, Date x, Calendar cal)
throws SQLException
{
logger.debug( "setDate(int parameterIndex, Date x, Calendar cal)");
if (x == null)
{
setNull(parameterIndex, Types.DATE);
}
else
{
// convert the date from to be in local time zone to be in UTC
String value = String.valueOf(x.getTime() +
cal.getTimeZone().getOffset(x.getTime()));
ParameterBindingDTO binding = new ParameterBindingDTO(
SnowflakeUtil.javaTypeToSFTypeString(Types.DATE), value);
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
}
@Override
public void setTime(int parameterIndex, Time x, Calendar cal)
throws SQLException
{
logger.debug( "setTime(int parameterIndex, Time x, Calendar cal)");
setTime(parameterIndex, x);
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
throws SQLException
{
logger.debug( "setTimestamp(int parameterIndex, Timestamp x, Calendar cal)");
// convert the time from being in UTC to be in local time zone
String value = null;
if (x != null)
{
long milliSecSinceEpoch = x.getTime();
milliSecSinceEpoch = milliSecSinceEpoch +
cal.getTimeZone().getOffset(milliSecSinceEpoch);
value = String.valueOf(
BigDecimal.valueOf(milliSecSinceEpoch / 1000).
scaleByPowerOfTen(9).add(BigDecimal.valueOf(x.getNanos())));
}
SnowflakeType sfType = SnowflakeUtil.javaTypeToSFType(Types.TIMESTAMP);
if (sfType == SnowflakeType.TIMESTAMP)
{
sfType = connection.getSfSession().getTimestampMappedType();
}
ParameterBindingDTO binding = new ParameterBindingDTO(sfType.name(), value);
parameterBindings.put(String.valueOf(parameterIndex), binding);
}
@Override
public void setNull(int parameterIndex, int sqlType, String typeName)
throws SQLException
{
logger.debug( "setNull(int parameterIndex, int sqlType, String typeName)");
setNull(parameterIndex, sqlType);
}
@Override
public void setURL(int parameterIndex, URL x) throws SQLException
{
throw new UnsupportedOperationException(
"setURL(int parameterIndex, URL x) Not supported yet.");
}
@Override
public ParameterMetaData getParameterMetaData() throws SQLException
{
throw new UnsupportedOperationException(
"getParameterMetaData() Not supported yet.");
}
@Override
public void setRowId(int parameterIndex, RowId x) throws SQLException
{
throw new UnsupportedOperationException(
"setRowId(int parameterIndex, RowId x) Not supported yet.");
}
@Override
public void setNString(int parameterIndex, String value) throws SQLException
{
throw new UnsupportedOperationException(
"setNString(int parameterIndex, String value) Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setNCharacterStream(int parameterIndex, Reader value, long length) Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, NClob value) throws SQLException
{
throw new UnsupportedOperationException(
"setNClob(int parameterIndex, NClob value) Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setClob(int parameterIndex, Reader reader, long length) Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setBlob(int parameterIndex, InputStream inputStream, long length) Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setNClob(int parameterIndex, Reader reader, long length) Not supported yet.");
}
@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject)
throws SQLException
{
throw new UnsupportedOperationException(
"setSQLXML(int parameterIndex, SQLXML xmlObject) Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType,
int scaleOrLength) throws SQLException
{
logger.debug(
"setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)");
if (x == null)
{
setNull(parameterIndex, targetSqlType);
}
else if (targetSqlType == Types.DECIMAL ||
targetSqlType == Types.NUMERIC)
{
BigDecimal decimalObj = new BigDecimal(String.valueOf(x));
decimalObj.setScale(scaleOrLength);
setBigDecimal(parameterIndex, decimalObj);
}
else
{
setObject(parameterIndex, x, targetSqlType);
}
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setAsciiStream(int parameterIndex, InputStream x, long length) Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setBinaryStream(int parameterIndex, InputStream x, long length) Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException(
"setCharacterStream(int parameterIndex, Reader reader, long length) Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x)
throws SQLException
{
throw new UnsupportedOperationException(
"setAsciiStream(int parameterIndex, InputStream x) Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x)
throws SQLException
{
throw new UnsupportedOperationException(
"setBinaryStream(int parameterIndex, InputStream x) Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader)
throws SQLException
{
throw new UnsupportedOperationException(
"setCharacterStream(int parameterIndex, Reader reader) Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value)
throws SQLException
{
throw new UnsupportedOperationException(
"setNCharacterStream(int parameterIndex, Reader value) Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException
{
throw new UnsupportedOperationException(
"setClob(int parameterIndex, Reader reader) Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream)
throws SQLException
{
throw new UnsupportedOperationException(
"setBlob(int parameterIndex, InputStream inputStream) Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException
{
throw new UnsupportedOperationException(
"setNClob(int parameterIndex, Reader reader) Not supported yet.");
}
@Override
public ResultSet executeQuery(String sql) throws SQLException
{
logger.debug( "executeQuery(String sql) throws SQLException");
throw new SnowflakeSQLException(ErrorCode.
UNSUPPORTED_STATEMENT_TYPE_IN_EXECUTION_API,
sql.length() > 20 ? sql.substring(0, 20) + "..." : sql);
}
@Override
public int executeUpdate(String sql) throws SQLException
{
logger.debug( "executeUpdate(String sql) throws SQLException");
throw new SnowflakeSQLException(ErrorCode.
UNSUPPORTED_STATEMENT_TYPE_IN_EXECUTION_API,
sql.length() > 20 ? sql.substring(0, 20) + "..." : sql);
}
@Override
public boolean execute(String sql) throws SQLException
{
logger.debug( "execute(String sql) throws SQLException");
throw new SnowflakeSQLException(ErrorCode.
UNSUPPORTED_STATEMENT_TYPE_IN_EXECUTION_API,
sql.length() > 20 ? sql.substring(0, 20) + "..." : sql);
}
@Override
public void addBatch(String sql) throws SQLException
{
throw new SnowflakeSQLException(ErrorCode.
UNSUPPORTED_STATEMENT_TYPE_IN_EXECUTION_API,
sql.length() > 20 ? sql.substring(0, 20) + "..." : sql);
}
@Override
public void clearBatch() throws SQLException
{
super.clearBatch();
batchParameterBindings.clear();
batchSize = 0;
sfStatement.setHasUnsupportedStageBind(false);
}
@Override
public int[] executeBatch() throws SQLException
{
logger.debug( "executeBatch() throws SQLException");
if (this.statementMetaData.getStatementType().isGenerateResultSet())
{
throw new SnowflakeSQLException(ErrorCode.
UNSUPPORTED_STATEMENT_TYPE_IN_EXECUTION_API,
sql.length() > 20 ? sql.substring(0, 20) + "..." : sql);
}
int[] updateCounts = null;
try
{
if (this.statementMetaData.isArrayBindSupported())
{
int updateCount = executeUpdateInternal(
this.sql, batchParameterBindings);
// when update count is the same as the number of bindings in the batch,
// expand the update count into an array (SNOW-14034)
if (updateCount == batchSize)
{
updateCounts = new int[updateCount];
for (int idx = 0; idx < updateCount; idx++)
updateCounts[idx] = 1;
}
else
{
updateCounts = new int[]{updateCount};
}
}
else
{
updateCounts = executeBatchInternal();
}
}
finally
{
this.clearBatch();
}
return updateCounts;
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys)
throws SQLException
{
throw new UnsupportedOperationException(
"executeUpdate(String sql, int autoGeneratedKeys) Not supported yet.");
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
{
throw new UnsupportedOperationException(
"executeUpdate(String sql, int[] columnIndexes) Not supported yet.");
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException
{
throw new UnsupportedOperationException(
"executeUpdate(String sql, String[] columnNames) Not supported yet.");
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
{
throw new UnsupportedOperationException(
"execute(String sql, int autoGeneratedKeys) Not supported yet.");
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException
{
throw new UnsupportedOperationException(
"execute(String sql, int[] columnIndexes) Not supported yet.");
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException
{
throw new UnsupportedOperationException(
"execute(String sql, String[] columnNames) Not supported yet.");
}
// For testing use only
Map<String, ParameterBindingDTO> getBatchParameterBindings()
{
return batchParameterBindings;
}
}