Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQlite default CURRENT_TIMESTAMP won't work; is inserted literally #40

Open
tripleee opened this issue May 10, 2016 · 3 comments
Open

Comments

@tripleee
Copy link
Contributor

tripleee commented May 10, 2016

Macaron inserts the literal string CURRENT_TIMESTAMP if I declare a table with a field like this;

create table example(
    id          integer  primary key,
    timestamp   datetime default CURRENT_TIMESTAMP
);

and create a new Example() with no explicit timestamp value.

@tripleee
Copy link
Contributor Author

tripleee commented Jun 8, 2016

I originally submitted a Bottle wishlist bug here; sorry for the mess.

@tripleee tripleee changed the title Multiple routes in one @route(..., ...) SQlite default CURRENT_TIMESTAMP won't work; is inserted literally Jun 9, 2016
@tripleee
Copy link
Contributor Author

tripleee commented Jun 9, 2016

Repro steps.

bash$ sqlite3 temp.db
sqlite> create table example(
...> id integer primary key,
...> timestamp datetime default CURRENT_TIMESTAMP
...> );
sqlite> insert into example (id) values (1);
sqlite> select * from example;
1|2016-06-09 08:31:11

So far so good. CURRENT_TIMESTAMP gets substituted.

bash$ python
>>> import macaron
>>> class Example(macaron.Model): pass
...
>>> macaron.macaronage(dbfile='temp.db')
>>> flawed = Example.create()
>>> macaron.bake()
>>> [x.timestamp for x in Example.all()]
[u'2016-06-09 08:31:11', u'CURRENT_TIMESTAMP']

@tripleee
Copy link
Contributor Author

tripleee commented Jun 9, 2016

A workaround is to define a before_create method in the Example class which populates self.timestamp with a suitable timestamp if it is None; but this obviously defeats the purpose of having SQlite supply a default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant