extend/bank_mysql — pull request #7 by matthias-endler (2013-06-08 17:17:59+00:00)
Title: add decimal support

Hi,

please review the code and tell me what you think about it.

https://github.com/pannonia-technologies/bank_mysql/commit/ce82b146e257bf77a2c3b65579ec0f68cbf46179

Please tell me if you want me to send a pull request. I'll then make the change to current HEAD.

Usage example in the shell:

```erl-sh
159> bank:prepare(test_db, insert_t3, "INSERT INTO t3 (amount) VALUES (?)").
ok
160> bank:prepare(test_db, select_t3, "SELECT * FROM t3").
ok
161> bank:execute(test_db, insert_t3, [{decimal, 12000, 5}]).
{ok,1,13}
162> bank:execute(test_db, select_t3, []).
{rows,[[{<<"id">>,1},{<<"amount">>,{decimal,3333350000,5}}],
[{<<"id">>,2},{<<"amount">>,{decimal,9999999999,5}}],
[{<<"id">>,3},{<<"amount">>,{decimal,1000000000,5}}],
[{<<"id">>,4},{<<"amount">>,null}],
[{<<"id">>,5},{<<"amount">>,{decimal,-100000,5}}],
[{<<"id">>,6},{<<"amount">>,{decimal,-1,5}}],
[{<<"id">>,7},{<<"amount">>,{decimal,0,5}}],
[{<<"id">>,8},{<<"amount">>,{decimal,-1,5}}],
[{<<"id">>,9},{<<"amount">>,{decimal,-1000000,5}}],
[{<<"id">>,10},{<<"amount">>,{decimal,-100000,5}}],
[{<<"id">>,11},{<<"amount">>,{decimal,-10000,5}}],
[{<<"id">>,12},{<<"amount">>,{decimal,-10000,5}}],
[{<<"id">>,13},{<<"amount">>,{decimal,12000,5}}]]}
```

This is when you query MySQL directly:

```
mysql> select * from t3;
+----+-------------+
| id | amount |
+----+-------------+
| 1 | 33333.50000 |
| 2 | 99999.99999 |
| 3 | 10000.00000 |
| 4 | NULL |
| 5 | -1.00000 |
| 6 | -0.00001 |
| 7 | 0.00000 |
| 8 | -0.00001 |
| 9 | -10.00000 |
| 10 | -1.00000 |
| 11 | -0.10000 |
| 12 | -0.10000 |
| 13 | 0.12000 |
+----+-------------+
13 rows in set (0.00 sec)
```
'matthias'.