Creating an SQL variable character column > 255 characters supporting multiple databases

Posted by Piers on Stack Overflow See other posts from Stack Overflow or by Piers
Published on 2010-05-08T09:34:33Z Indexed on 2010/05/08 9:38 UTC
Read the original article Hit count: 274

Filed under:
|

I have an application that stores data through an ODBC data source of the user's choosing. So far it has worked well on a range of database systems (e.g. JET, Oracle, SQL Server), as the SQL syntax is fairly simple.

Now I am running into a problem where I need to store more than 255 characters in my strings. Previously I created the table using column type VARCHAR (255).

Now if I try to create a table using, e.g. VARCHAR (512) then it falls over on Access databases. I know that I can use the MEMO type for Access, but this is non-standard SQL and will thus likely fail on other database systems (e.g. Oracle).

Is there any widely supported SQL standard for creating text columns wider than 255 characters, or do I need to find another solution? The alternatives seem to me to be:

1) Profile the database system and customise the SQL CREATE TABLE command based on the database system. I don't like this as it defeats the purpose of using ODBC.

2) Add extra columns of 255 chars as required (e.g. LONGSTRING1, LONGSTRING2, ...) and concatenate after reading. I don't like this because it means the number of columns can vary between tables and it complicates read/write.

Are there any other viable alternatives to these two options? Or is it possible to have an SQL compliant CREATE TABLE command supported by the majority of database vendors, that supports strings longer than 255 chars?

© Stack Overflow or respective owner

Related posts about sql

Related posts about odbc