/
PositionedParameters.scala
148 lines (141 loc) · 7.29 KB
/
PositionedParameters.scala
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
package slick.jdbc
import java.sql.{PreparedStatement, Date, Time, Timestamp, Types, Blob, Clob}
/** A wrapper for a JDBC `PreparedStatement` which allows inceremental setting of
* parameters without having to sepcify the column index each time. */
class PositionedParameters(val ps: PreparedStatement) {
var pos = 0
/** Set the next parameter of the specified type, provided that a
* `SetParameter` instance is available for it. */
def >> [T](value: T)(implicit f: SetParameter[T]): Unit = f(value, this)
/** Set the next parameter to SQL NULL with the specified SQL type code. */
def setNull(sqlType: Int): Unit = { val npos = pos + 1; ps.setNull(npos, sqlType); pos = npos }
/** Set the next parameter */
def setBoolean(value: Boolean): Unit = { val npos = pos + 1; ps.setBoolean (npos, value); pos = npos }
/** Set the next parameter */
def setBlob(value: Blob): Unit = { val npos = pos + 1; ps.setBlob (npos, value); pos = npos }
/** Set the next parameter */
def setByte(value: Byte): Unit = { val npos = pos + 1; ps.setByte (npos, value); pos = npos }
/** Set the next parameter */
def setBytes(value: Array[Byte]): Unit = { val npos = pos + 1; ps.setBytes (npos, value); pos = npos }
/** Set the next parameter */
def setClob(value: Clob): Unit = { val npos = pos + 1; ps.setClob (npos, value); pos = npos }
/** Set the next parameter */
def setDate(value: Date): Unit = { val npos = pos + 1; ps.setDate (npos, value); pos = npos }
/** Set the next parameter */
def setDouble(value: Double): Unit = { val npos = pos + 1; ps.setDouble (npos, value); pos = npos }
/** Set the next parameter */
def setFloat(value: Float): Unit = { val npos = pos + 1; ps.setFloat (npos, value); pos = npos }
/** Set the next parameter */
def setInt(value: Int): Unit = { val npos = pos + 1; ps.setInt (npos, value); pos = npos }
/** Set the next parameter */
def setLong(value: Long): Unit = { val npos = pos + 1; ps.setLong (npos, value); pos = npos }
/** Set the next parameter */
def setShort(value: Short): Unit = { val npos = pos + 1; ps.setShort (npos, value); pos = npos }
/** Set the next parameter */
def setString(value: String): Unit = { val npos = pos + 1; ps.setString (npos, value); pos = npos }
/** Set the next parameter */
def setTime(value: Time): Unit = { val npos = pos + 1; ps.setTime (npos, value); pos = npos }
/** Set the next parameter */
def setTimestamp(value: Timestamp): Unit = { val npos = pos + 1; ps.setTimestamp (npos, value); pos = npos }
/** Set the next parameter */
def setBigDecimal(value: BigDecimal): Unit = { val npos = pos + 1; ps.setBigDecimal(npos, value.bigDecimal); pos = npos }
/** Set the next parameter to an object of a driver-specific type that
* corresponds to the specified SQL type code. */
def setObject(value: AnyRef, sqlType: Int): Unit = { val npos = pos + 1; ps.setObject(npos, value, sqlType); pos = npos }
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setBooleanOption(value: Option[Boolean]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.BOOLEAN) else ps.setBoolean(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setBlobOption(value: Option[Blob]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.BLOB) else ps.setBlob(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setByteOption(value: Option[Byte]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.TINYINT) else ps.setByte(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setBytesOption(value: Option[Array[Byte]]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.BLOB) else ps.setBytes(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setClobOption(value: Option[Clob]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.CLOB) else ps.setClob(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setDateOption(value: Option[Date]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.DATE) else ps.setDate(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setDoubleOption(value: Option[Double]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.DOUBLE) else ps.setDouble(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setFloatOption(value: Option[Float]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.FLOAT) else ps.setFloat(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setIntOption(value: Option[Int]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.INTEGER) else ps.setInt(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setLongOption(value: Option[Long]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.INTEGER) else ps.setLong(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setShortOption(value: Option[Short]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.SMALLINT) else ps.setShort(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setStringOption(value: Option[String]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.VARCHAR) else ps.setString(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setTimeOption(value: Option[Time]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.TIME) else ps.setTime(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setTimestampOption(value: Option[Timestamp]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.TIMESTAMP) else ps.setTimestamp(npos, value.get)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setBigDecimalOption(value: Option[BigDecimal]): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, Types.DECIMAL) else ps.setBigDecimal(npos, value.get.bigDecimal)
pos = npos
}
/** Set the next parameter to the specified value or a properly typed SQL NULL */
def setObjectOption(value: Option[AnyRef], sqlType: Int): Unit = {
val npos = pos + 1
if(value eq None) ps.setNull(npos, sqlType) else ps.setObject(npos, value.get, sqlType)
pos = npos
}
}