AIR 1.0対応で手間取ったこと:Dateと実行時の型変換
DBでDATETIME型で保存していたのですが、1.0で動かそうとしたらupdated_at
修正したところ
- DB側はDATETIMEではなくてDATEに
下にあるように親和性が高いカラムのほうが楽だと判断しDATE型にしました。DATEといっても日付と時間も格納してくれます。 - parameterで渡すのはDateのインスタンスで
getTime()だとNumberが帰ってしまうので、INSERTはOKなんだけど、SELECTしてblog.updated_atとすると”Invalid Date”といわれてしまう。
1 stmt.parameter[":updated_a t"] = new Date(); //OK 2 stmt.param eter[":updated_a t"] = new Date().getTime(); //NG:beta3までは動いてた
サポートされるSQLの仕様:local database
http://liv
サポートされる型で特に親和性が高いもの
The affinity of a column is the recommende
d type for data stored in that column. When a value is stored in a column (through an INSERT or UPDATE statement), the runtime attempts to convert that value from its data type to the specified affinity
http://livedocs.adob e.com/air/ 1/jslr/loc alDatabase SQLSupport .html#columnAffi nit
下記のカラムとは親和性があり、実行時にデータ型を変換してくれるそうです。
- TEXT (or STRING)
- NUMERIC
- INTEGER
- REAL (or NUMBER)
- BOOLEAN
- DATE
- XML
- XMLLIST
- OBJECT
- NONE
DATEの親和性
A column with DATE affinity stores date and time values. A DATE column is designed to accept values that are ActionScri
pt or JavaScript Date instances. If an attempt is made to store a String value in a DATE column, the runtime attempts to convert it to a Julian date. If the conversion fails an error occurs. If code attempts to store a Number, int, or uint value, no attempt is made to validate the data and it is assumed to be a valid Julian date value. A DATE value that's retrieved using a SELECT statement is automatica lly converted to a Date instance. DATE values are stored as Julian date values using the REAL storage class, so sorting and comparing operations work as you would expect them to.
NOTE:太字は私が強調をつけたところです。