Data Type Mismatchs Between Relational Db And Host Language

[Moved from RelationalHostLanguageImpedanceMismatch.]

Select a widely accepted relational database product and a widely used host language. Regardless of your selections, you can be sure that the set of data types supported by the database, for defining tables, is different from the set of data types available in the host language.

With older languages, like C and COBOL, modern databases often have data types not supported by the host language. With more modern languages, and with most OO languages, the host language has more types than the database.

The two are different. Therefore there is a mismatch.

You could restrict yourself to the intersection of the relational and host language data type sets, but then you'd lose the benefits of the other types not available on "the other" platform. And where's the business requirement that says that all businesses must have a requirement that all data be equally processable in both the relational database's SQL and the host language of choice?


With respect to the host language, you might consider...

(Because OO languages typically have more usable data types than relational databases, adding libraries and custom code typically makes the mismatch worse, not better.)


Data Type Mismatches:

Relational database data types often don't map one-to-one with host language data types:

No, you cannot. you can't blame Oracle for this, after all Oracle doesn't force you to use NUMBER(5). But on the other hand, depending on your particular language you can have a NumberValue? class

Well, Oracle accepts Double as a type. use Double or used a fixed decimal AND create a class/ or user defined struct together with functions to operate with exactly the same semantics as in Oracle

I really don't know about VB, but in C you can easily define struct bounded_string {int length, char* data} and define some functions that operate on this struct by checking for length and forwarding the calls to string.h functions. Again, you really mean that the host language should be extended a little bit.

Well, you have a TEXT or CLOB data type in most relational databases that deal with unbounded texts. Watch carefully, if you really want to manipulate strings that you cannot predict that will have a reasonable upper bound to their length, you have to rethink your design, even for the host language. Even in this case a database is more capable of dealing with large pieces of data than a programming language. Of course no database can take no matter what abuse.

[New comment as of 7/26 evening:] When I wrote programs in the PICK operating system, I didn't have to impose the technical requirement on my business requirements that all strings have a fixed maximum length: Names, addresses, product descriptions, and all other strings could be as short or as long as needed. Now, because I'm "blessed" with a real relational database, I have to limit my business requirements to the database's limitations? Somehow I fail to see this part of it as an improvement. (TEXT columns aren't the answer either: Can't index. Can't process in SQL with "=" or "like". And the overhead of using them on strings of less than several K bytes in size is really nasty.)

Say I do pick a large "reasonable upper bound" to my varchar columns. Throw a few together in a record, exceed Oracle's 2K limit on record size, and you're stuck again.

The above assessment about Oracle is just not true, and it is not true for any modern RDBMS. In general all relational databases put a reasonable limit (2k or 4k - for newer verison of Oracle it is 4K) on VARCHAR columns. To pretend you need more than that, and you do not to use CLOB columns is deluding yourself. The row itself can be as big as 1GB and bigger, it is not limmited to 2k, however if you grow it too big you'll have to suffer some consequences. Yes the CLOBs columns cannot be used directly in an index, but anything that grows any bigger than a reasonable size, and 2K is way more than reasonable for a simple String, cannot be meaningfully used for an index, based on its intrinsic value. -CostinCozianu


No, in general you don't need mapping if you are happy with only built-in data types offered to you in the host language(like double, float, int, String and the likes). Otherwise you can't blame the impedance mismatch because it doesn't offer you a VARCHAR(15) CHECK // various checks ... here. -- CostinCozianu


Simple solution:

Just use a highly dynamic language with a dynamic database (see MultiParadigmDatabase). It seems that too many DB vendors are obsessed with benchmarks, and put flexibility and adaptability last. It does not have to be this way.


CategoryRelationalDatabase


EditText of this page (last edited December 24, 2004) or FindPage with title or text search