• 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

DBでDATETIME型で保存していたのですが、1.0で動かそうとしたらupdated_at(flash側ではDate)がInvalidDateと表示されてしまう。MYSQLクライアントでSELECTしたら特に問題なさそう。??と思ったのですが動いたのでメモ。

修正したところ

  • DB側はDATETIMEではなくてDATE
    下にあるように親和性が高いカラムのほうが楽だと判断しDATE型にしました。DATEといっても日付と時間も格納してくれます。
  • parameterで渡すのはDateのインスタンス
    getTime()だとNumberが帰ってしまうので、INSERTはOKなんだけど、SELECTしてblog.updated_atとすると”Invalid Date”といわれてしまう。

   1  stmt.parameter[":updated_at"] = new Date(); //OK
   2  stmt.parameter[":updated_at"] = new Date().getTime(); //NG:beta3までは動いてた

サポートされるSQLの仕様:local database

http://livedocs.adobe.com/air/1/jslr/localDatabaseSQLSupport.html

サポートされる型で特に親和性が高いもの

The affinity of a column is the recommended 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.adobe.com/air/1/jslr/localDatabaseSQLSupport.html#columnAffinit

下記のカラムとは親和性があり、実行時にデータ型を変換してくれるそうです。

  • 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 ActionScript 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 automatically 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:太字は私が強調をつけたところです。

posted by Png satoko on Wed 26 Mar 2008 at 10:08

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry488
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ