@@ -39,17 +39,21 @@ public class PrestoPreparedStatement
39
39
extends PrestoStatement
40
40
implements PreparedStatement
41
41
{
42
+ private String sql ;
43
+
42
44
PrestoPreparedStatement (PrestoConnection connection , String sql )
43
45
throws SQLException
44
46
{
45
47
super (connection );
48
+ this .sql = sql ;
46
49
}
47
50
48
51
@ Override
49
52
public ResultSet executeQuery ()
50
53
throws SQLException
51
54
{
52
- throw new NotImplementedException ("PreparedStatement" , "executeQuery" );
55
+ sql = sql .replaceAll ("([?])" , "null" );
56
+ return super .executeQuery (sql );
53
57
}
54
58
55
59
@ Override
@@ -59,6 +63,11 @@ public int executeUpdate()
59
63
throw new NotImplementedException ("PreparedStatement" , "executeUpdate" );
60
64
}
61
65
66
+ private String replaceQueryParam (String sql , String value )
67
+ {
68
+ return sql .replaceFirst ("([?])" , value );
69
+ }
70
+
62
71
@ Override
63
72
public void setNull (int parameterIndex , int sqlType )
64
73
throws SQLException
@@ -84,42 +93,42 @@ public void setByte(int parameterIndex, byte x)
84
93
public void setShort (int parameterIndex , short x )
85
94
throws SQLException
86
95
{
87
- throw new NotImplementedException ( "PreparedStatement" , "setShort" );
96
+ sql = replaceQueryParam ( sql , Integer . toString ( x ) );
88
97
}
89
98
90
99
@ Override
91
100
public void setInt (int parameterIndex , int x )
92
101
throws SQLException
93
102
{
94
- throw new NotImplementedException ( "PreparedStatement" , "setInt" );
103
+ sql = replaceQueryParam ( sql , Integer . toString ( x ) );
95
104
}
96
105
97
106
@ Override
98
107
public void setLong (int parameterIndex , long x )
99
108
throws SQLException
100
109
{
101
- throw new NotImplementedException ( "PreparedStatement" , "setLong" );
110
+ sql = replaceQueryParam ( sql , Long . toString ( x ) );
102
111
}
103
112
104
113
@ Override
105
114
public void setFloat (int parameterIndex , float x )
106
115
throws SQLException
107
116
{
108
- throw new NotImplementedException ( "PreparedStatement" , "setFloat" );
117
+ sql = replaceQueryParam ( sql , Float . toString ( x ) );
109
118
}
110
119
111
120
@ Override
112
121
public void setDouble (int parameterIndex , double x )
113
122
throws SQLException
114
123
{
115
- throw new NotImplementedException ( "PreparedStatement" , "setDouble" );
124
+ sql = replaceQueryParam ( sql , Double . toString ( x ) );
116
125
}
117
126
118
127
@ Override
119
128
public void setBigDecimal (int parameterIndex , BigDecimal x )
120
129
throws SQLException
121
130
{
122
- throw new NotImplementedException ( "PreparedStatement" , "setBigDecimal" );
131
+ sql = replaceQueryParam ( sql , x . toString () );
123
132
}
124
133
125
134
@ Override
@@ -182,7 +191,6 @@ public void setBinaryStream(int parameterIndex, InputStream x, int length)
182
191
public void clearParameters ()
183
192
throws SQLException
184
193
{
185
- throw new NotImplementedException ("PreparedStatement" , "clearParameters" );
186
194
}
187
195
188
196
@ Override
@@ -196,7 +204,20 @@ public void setObject(int parameterIndex, Object x, int targetSqlType)
196
204
public void setObject (int parameterIndex , Object x )
197
205
throws SQLException
198
206
{
199
- throw new NotImplementedException ("PreparedStatement" , "setObject" );
207
+ if (x instanceof String )
208
+ sql = sql .replaceFirst ("([?])" , "'" + x .toString () + "'" );
209
+ else if (x instanceof BigDecimal )
210
+ setBigDecimal (parameterIndex , (BigDecimal )x );
211
+ else if (x instanceof Short )
212
+ setShort (parameterIndex , (Short ) x );
213
+ else if (x instanceof Integer )
214
+ setInt (parameterIndex , (Integer ) x );
215
+ else if (x instanceof Long )
216
+ setLong (parameterIndex , (Long ) x );
217
+ else if (x instanceof Float )
218
+ setFloat (parameterIndex , (Float ) x );
219
+ else if (x instanceof Double )
220
+ setDouble (parameterIndex , (Double ) x );
200
221
}
201
222
202
223
@ Override
0 commit comments