Re: Extract String From Enclosing Tuple



rshepard@xxxxxxxxxxxxxxxxxxxxxx writes:

Data are assembled for writing to a database table. A
representative tuple looks like this:

('eco', "(u'Roads',)", 0.073969887301348305)

You refer to the second item as "a tuple" later, but it's not; it's
now just a string (not even a unicode string). Whatever has assembled
these has effectively lost the structure of the data and you are now
left with three items in a tuple: string, string, float.

Some RDBMSs can store a structure of multiple values in one value;
SQLite cannot. The usual solution for this limitation is to take these
structural values and store the component values as separate rows of a
different table, and have each of those rows refer back to the
identifying key of the original table so they can be joined easily.

E.g., I might conceptually think of order records as the following
tuples, with further tuples-of-tuples for the items on each order:

orders = (
# fields: id, cust_code, date, order_items
(1, "cust1234", "2007-02-15", (("item002", 1), ("item005", 3), ("item007", 1))),
(2, "cust4567", "2007-02-19", (("item001", 5), ("item005", 2))),
)

Since I can't store those as-is in SQLite, I would need to restructure
the tables: separate the "order items" to separate rows in a dedicated
table, and refer to the "order" table key in each "order item" row.

orders = (
# fields: id, cust_code, date
(1, "cust1234", "2007-02-15"),
(2, "cust4567", "2007-02-19"),
)

order_items = (
# fields: id, order_id, item_code, quantity
(1, 1, "item002", 1),
(2, 1, "item005", 3),
(3, 1, "item007", 1),
(4, 2, "item001", 5),
(5, 2, "item005", 2),
)

Then you can use SQL JOIN clauses as necessary, with the
order_item.order_id field a foreign key into the order table.

--
\ "I moved into an all-electric house. I forgot and left the |
`\ porch light on all day. When I got home the front door wouldn't |
_o__) open." -- Steven Wright |
Ben Finney

.



Relevant Pages

  • RfD: Directories
    ... How do I refer to another file that is distributed with the ... The source file of the string is important for the expansion, ... where the consumer is not in the same file as the string); ... current working directory (unfortunately not the directory containing ...
    (comp.lang.forth)
  • Re: The operator of "==" in String
    ... > The book says that when i define two String a and b, they will refer to ... versions of Java, not just 1.5. ... objects from being created from the same text string. ... Those rules say that when two COMPILE-TIME CONSTANT strings appear in ...
    (comp.lang.java.programmer)
  • Re: Advanced Javascript Object question
    ... >> put a variable in place of the fixed text string it said that the ... If you want to refer to "this" object of the assignment inside ... I have an object (a slider) which has an "onchange" event ...
    (comp.lang.javascript)
  • link 2 exes?
    ... Now I am developing one more application(I will refer ... and then will pass a parameter (say a string) to this old ... that the new applicaiton is visible first. ...
    (comp.soft-sys.matlab)
  • RE: Get right Excel application
    ... I can refer it at any time. ... is correct since the macro code is always inside the right excel file. ... Set oXlRng = ThisWorkbook.Sheets.SheetName).Range ... CodeName As String 'Long Name ...
    (microsoft.public.excel.programming)