svn-gvsig-desktop / tags / v1_0_2_Build_914 / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / engine / values / ValueWriterImpl.java @ 12200
History | View | Annotate | Download (2.75 KB)
1 |
package com.hardcode.gdbms.engine.values; |
---|---|
2 |
|
3 |
import java.sql.Date; |
4 |
import java.sql.Time; |
5 |
import java.sql.Timestamp; |
6 |
import java.text.DateFormat; |
7 |
import java.text.SimpleDateFormat; |
8 |
|
9 |
/**
|
10 |
* @author Fernando Gonz?lez Cort?s
|
11 |
*/
|
12 |
class ValueWriterImpl implements ValueWriter{ |
13 |
|
14 |
private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); |
15 |
|
16 |
/**
|
17 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(long)
|
18 |
*/
|
19 |
public String getStatementString(long i) { |
20 |
return Long.toString(i); |
21 |
} |
22 |
|
23 |
/**
|
24 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(int, int)
|
25 |
*/
|
26 |
public String getStatementString(int i, int sqlType) { |
27 |
return Integer.toString(i); |
28 |
} |
29 |
|
30 |
/**
|
31 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(double, int)
|
32 |
*/
|
33 |
public String getStatementString(double d, int sqlType) { |
34 |
return Double.toString(d); |
35 |
} |
36 |
|
37 |
/**
|
38 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(java.lang.String, int)
|
39 |
*/
|
40 |
public String getStatementString(String str, int sqlType) { |
41 |
return "'" + escapeString(str) + "'"; |
42 |
} |
43 |
|
44 |
/**
|
45 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(java.sql.Date)
|
46 |
*/
|
47 |
public String getStatementString(Date d) { |
48 |
return "'" + d.toString() + "'"; |
49 |
} |
50 |
|
51 |
/**
|
52 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(java.sql.Time)
|
53 |
*/
|
54 |
public String getStatementString(Time t) { |
55 |
return "'" + timeFormat.format(t) + "'"; |
56 |
} |
57 |
|
58 |
/**
|
59 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(java.sql.Timestamp)
|
60 |
*/
|
61 |
public String getStatementString(Timestamp ts) { |
62 |
return "'" + ts.toString() + "'"; |
63 |
} |
64 |
|
65 |
/**
|
66 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(byte[])
|
67 |
*/
|
68 |
public String getStatementString(byte[] binary) { |
69 |
StringBuffer sb = new StringBuffer("'"); |
70 |
for (int i = 0; i < binary.length; i++) { |
71 |
int byte_ = binary[i];
|
72 |
if (byte_ < 0) byte_ = byte_ + 256; |
73 |
String b = Integer.toHexString(byte_); |
74 |
if (b.length() == 1) sb.append("0").append(b); |
75 |
else sb.append(b);
|
76 |
|
77 |
} |
78 |
sb.append("'");
|
79 |
|
80 |
return sb.toString();
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getStatementString(boolean)
|
85 |
*/
|
86 |
public String getStatementString(boolean b) { |
87 |
return Boolean.toString(b); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see com.hardcode.gdbms.engine.values.ValueWriter#getNullStatementString()
|
92 |
*/
|
93 |
public String getNullStatementString() { |
94 |
return "null"; |
95 |
} |
96 |
|
97 |
static String escapeString(String string){ |
98 |
return string.replaceAll("\\Q'\\E", "''"); |
99 |
} |
100 |
|
101 |
} |