Skip to main content

Posts

Showing posts with the label sqlite

Life Isn't What It's All Cracked Up To Be!

Life isn’t what everyone says it’s like. I’d like to think it’s something unique, but well it’s not. It’s something that comes along to everyone. We don’t have a say in the matter. We live, we live and we die. There’s nothing much else to it. I mean, if there were? Wouldn’t you think we could explain why everything works the way it does? Yeah, that’s what I was thinking. But we don’t get to have that choice in life. It’s a damning thing to make us worry over everything and nothing at all. But that’s life in a nutshell isn’t it? Yeah, that’s what I was thinking.

SQLite and Dates

Sometimes we want to store the date/time as an integer. It makes sense sometimes. If you want to run updates on everything higher than a certain number, you can do it quite easily with an integer. If you want to run everything all over again, compare it to zero. All records will be processed again. Easy peasy. Here’s how one of my tables looks to achieve this integer method for a date/time: CREATE TABLE notes( id INTEGER primary key, title TEXT, note_txt TEXT, created_dt INTEGER not null default (strftime('%s', 'now', 'localtime')), exported_flag INTEGER not null default 0 ); See how that works? Yeah, it’s pretty neat if I do say so myself. Of course you have to convert it to make it human readable. To do that, I usually do something like this: SELECT id, title, note_txt, created_dt, strftime('%Y-%m-%d %H:%M', created_dt) as formatted_dt FROM notes ORDER BY id DESC LIMIT 1 But, I can see what you’re thinking. Why do it...

SQLite Read File

There is a simple way to read a file into a SQLite database. The syntax looks like this: INSERT INTO images(name, img) VALUES('my_photo', readfile('photo.jpg')); Naturally you wouldn’t want to do this for very large files. The database would grow rather large I would expect and might become unmanagable. But for small files like icons? Things like that? Yeah I don’t see why not. Seems like such a simple little thing to do doesn’t it. Yeah, that’s what I was thinking.