I'd like to write code that uses
DBI and that works without modification with SQLite and Oracle databases. The first issue I've run into is automatically incrementing fields: I know MySQL has them, and I guess I'd be using them if my target DB were MySQL.
But SQLite seems to have, but not to like them; and Oracle (my target version is 9) doesn't have them at all, offering sequences instead. I found a page explaining how to emulate autoincrement on Oracle but I couldn't see how to get the last_insert_id out of it.
Okay, so suppose I go with explicit sequences. I don't really need autoincrement, I can use sequences if they're available. How do they work in SQLite? Do they work there at all? That page I linked to above is confusing me.
So my primary question is: what's the syntax for creating and using sequences in SQLite?
Further questions:
- Is this the way to go?
- What would you suggest as a good technique to minimize my unportable SQL?
- What other issues should I be wary of in writing code for Oracle and SQLite?
As you can see, I'm no database expert. I have read Auto-Increment and DBD Agnosticism and Re: Generating portable SQL primary key sequences but didn't find everything I need there. Note that I do know my two specific target DBDs, and am asking about the best practices with them.
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.