Permalink
Browse files

Changed order of Expect params

Can now write dates
  • Loading branch information...
1 parent 3a6253c commit 3c3721ad2bed38189ae49153cbefe2ace6476ad2 @jamesots committed Apr 17, 2012
Showing with 38 additions and 11 deletions.
  1. +17 −0 lib/handlers/prepared_statements.dart
  2. +2 −2 main.dart
  3. +19 −9 tests/mathstest.dart
@@ -210,6 +210,23 @@ class ExecuteQueryHandler extends Handler {
types.add(FIELD_TYPE_FLOAT);
types.add(0);
values.addAll(floatToList(value));
+ } else if (value is Date) {
+ log.debug("DATE: $value");
+ types.add(FIELD_TYPE_DATETIME);
+ types.add(0);
+ values.add(12);
+ values.add(value.year & 0xFF);
+ values.add(value.year >> 8 & 0xFF);
+ values.add(value.month);
+ values.add(value.day);
+ values.add(value.hours);
+ values.add(value.minutes);
+ values.add(value.seconds);
+ int billionths = value.milliseconds * 1000000;
+ values.add(billionths & 0xFF);
+ values.add(billionths >> 8 & 0xFF);
+ values.add(billionths >> 16 & 0xFF);
+ values.add(billionths >> 24 & 0xFF);
} else if (value is bool) {
log.debug("BOOL: $value");
types.add(FIELD_TYPE_TINY);
View
@@ -66,8 +66,8 @@ void testPreparedQuery(AsyncConnection cnx, Log log) {
void testPreparedQuery2(AsyncConnection cnx, Log log) {
log.debug('------------------------');
- cnx.prepare("update types set aboolean = ?").then((query) {
- query[0] = true;
+ cnx.prepare("update types set adatetime = ?").then((query) {
+ query[0] = new Date.now();
var res = query.execute().then((dummy) {
query.close();
log.debug("stmt closed");
View
@@ -2,49 +2,59 @@ class MathsTest {
void canWriteZero() {
double n = 0.0;
List<int> bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "00000000");
+ Expect.equals("00000000", listToHexString(bytes, true));
}
void canWriteOneOrGreater() {
double n = 1.0;
List<int> bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "3F800000");
+ Expect.equals("3F800000", listToHexString(bytes, true));
n = 100.0;
bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "42C80000");
+ Expect.equals("42C80000", listToHexString(bytes, true));
n = 123487.982374;
bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "47F12FFD");
+ Expect.equals("47F12FFD", listToHexString(bytes, true));
n = 10000000000000000000000000000.0;
bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "6E013F39");
+ Expect.equals("6E013F39", listToHexString(bytes, true));
// TODO: test very large numbers
}
void canWriteLessThanOne() {
double n = 0.1;
List<int> bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "3DCCCCCC");
+ Expect.equals("3DCCCCCC", listToHexString(bytes, true));
// TODO: test very small numbers
+ n = 3.4028234663852886E+38;
+ print(n);
+ bytes = floatToList(n);
+ Expect.equals("7F7FFFFF", listToHexString(bytes, true));
+
+ n = 1.1754943508222875E-38;
+ print(n);
+ bytes = floatToList(n);
+ Expect.equals("00800000", listToHexString(bytes, true));
}
+
void canWriteNonNumbers() {
double n = 1.0/0.0;
List<int> bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "7F800000");
+ Expect.equals("7F800000", listToHexString(bytes, true));
n = -1.0/0.0;
bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "F8000000");
+ Expect.equals("F8000000", listToHexString(bytes, true));
n = 0.0/0.0;
bytes = floatToList(n);
- Expect.equals(listToHexString(bytes, true), "7F800001");
+ Expect.equals("7F800001", listToHexString(bytes, true));
}
void runAll() {

0 comments on commit 3c3721a

Please sign in to comment.