I'm not sure, that Date object will be passed as a parameter correctly. Try this:
sqlWrapper.statement.parameters[":lastLogin"] = (new Date()).toISOString();
Question
I am attempting to insert data into a SQLite database, including a date column. However when I execute the query in the code below the LastLogin
field is never populated. Also, the Created
field is also left empty, even though the default value is CURRENT_TIMESTAMP
. All other fields in the query populate correctly. Can anyone tell me why this is?
This is the table SQL in SQLite:
CREATE TABLE [User] (
[Id] INTEGER PRIMARY KEY NOT NULL,
[CredentialsToken] TEXT NULL,
[GivenName] TEXT NULL,
[FamilyName] TEXT NULL,
[Created] DATE DEFAULT CURRENT_TIMESTAMP NULL,
[LastUpdated] DATE NULL,
[LastLogin] DATE NULL
)
This is my AS inserting the data:
private const CREATE_USER:String = "INSERT INTO User (Id, CredentialsToken, GivenName, FamilyName, LastLogin) VALUES (:id, :token, :givenName, :familyName, :lastLogin)";
public function createUser(args:Array):void
{
if (args[0] is DatabaseResponder && args[1] is Object)
{
var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], CREATE_USER);
var user:Object = args[1];
sqlWrapper.statement.parameters[":id"] = user.Id;
sqlWrapper.statement.parameters[":token"] = user.LoginToken;
sqlWrapper.statement.parameters[":givenName"] = user.GivenName;
sqlWrapper.statement.parameters[":familyName"] = user.FamilyName;
sqlWrapper.statement.parameters[":lastLogin"] = new Date(); // this field is always empty
sqlWrapper.statement.execute();
}
}
Also worth noting is the fact that when I execute the following SQL through SQLite Administrator, the LastLogin
field is still left empty, although Created
does get populated.
INSERT INTO User (Id, CredentialsToken, GivenName, FamilyName, LastLogin) VALUES (111, 'XYZ', 'Foo', 'Bar', '29-10-2013')
Solution
I'm not sure, that Date object will be passed as a parameter correctly. Try this:
sqlWrapper.statement.parameters[":lastLogin"] = (new Date()).toISOString();