database technique

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kfaw
    New Member
    • Apr 2010
    • 1

    #1

    database technique

    I'm currently working with c++ code that stores strings to a LONG_VARCHAR in a db2 table. The strings contain different data at defined offsets within the string. A "type" value is stored in another column with each string entry. This "type" value is used to decode the string - the "type" value defines what data the string contains and ultimately the offset of the data in the strings. As an example:
    A data string for a power supply might look like this:
    "3 1.3 3.5 1.355 " - the first 3 indicates the number of outputs and the next values indicates the current reading of these outputs.
    A data string for flow sensors might look like this:
    "2 0 5.35 7 4.25 " - 2=number of sensors, 0 =location 0, 5.35 location 0 flow reading, 7=location 7, 4.25=location 7 flow reading.

    A program displaying the results would get the string (the first string) along with the data type (and then know it's power supply data) then generate the following output:

    "Power supply has 3 outputs - output 0=1.3/output1=3.5/output 2=1.355 "

    This approach works, but it's prone to errors, inflexible ( can't readily add new data or increase the width of a value and it messes up external programs that parse these strings). I can understand the common LONG_VARCHAR column/string approach has some merit because the data stored contains different types and amounts (sometimes hundreds of values) of data, but is there a better approach to storing variable data/types in a database?
Working...