To answer your most basic question, the best way to insert structure values
into a database would be to parse each value of the structure into a local
variable and insert those values.  Structures are complex objects and
database fields are simple constructs.


Investigate looping over the values of a structure.
http://www.kodefusion.com/article/index.cfm?ArticleID=2

  _____  

From: Tim Laureska [mailto:[EMAIL PROTECTED]
Sent: Friday, September 10, 2004 8:52 AM
To: CF-Talk
Subject: RE: inserting structure data into a database

body>
Wow, that was a great "array" of responses ...the code for inserting the
data that I have played with initially is below.  I'm really looking to
understand what the best way of inserting data from a structure into a
database... is this an illogical question to begin with?  

<cfset me = structNew()>
<cfset me.mytitle = "#form.title#">
<cfset me.mydate1 = "#form.date1#">
<cfset me.mypublication = "#form.publication#">
<cfset me.myissue = "#form.issue#">

<cfoutput>
<table>
  <cfloop from="1" to="#ListLen(item1)#" index="i">
   <tr>
    <td valign="top">#ListGetAt(item1, i)#&nbsp;&nbsp;</td>
    <td valign="top">#ListGetAt(item2, i)#&nbsp;&nbsp;</td>
    <td valign="top">#ListGetAt(item3, i)#</td>
   </tr>
  </cfloop>
</table>
</cfoutput>

<cfquery datasource="library_56">
INSERT INTO test_structures (test1, test2, test3, structure)
Values ('#item1#', '#item2#', '#item3#', #me#)
</cfquery>

-----Original Message-----
From: Dick Applebaum [mailto:[EMAIL PROTECTED]
Sent: Friday, September 10, 2004 8:32 AM
To: CF-Talk
Subject: Re: inserting structure data into a database

Tim

One of the basic rules of good relational db design is that each entity
(record, row, column) should be atomic -- represent only one thing,

You should not insert a structure into a db

Rather, insert each cassette as a separate row (record) in the db

If there is a relationship among the multiple cassettes that you
currently have in the structure, consider adding an identifier (group)
to each record in the db.

   ID
   Title
   IssueNumber
   IssueDate
   Group

Dick

On Sep 10, 2004, at 5:23 AM, Tim Laureska wrote:

> Just learning structures, but here goes:
>
>  When I insert structure data into a database, it's inserted into each
>  field as a comma delimited list.  
>
>  In this scenario, I'm inserting audio cassette tape information into
> the
>  database from a form when multiple cassettes are entered at one time.
>  There are three attributes to for each cassette... title, issue date
> and
>  issue number, which are the fields in the database (along with an
> autoid
>  field).
>
>  So if three cassettes are entered and subsequently inserted into the
>  database, the data goes in as such:
>
>  Auto id    title field        issue number field     issue date
>  field
>
>     1       title1, title2, title3  issue1,issue2,issue3
>  date1,date2,date3
>
>  This seems to present a problem in that each cassette does not have a
>  unique autoid to identify it individually and that may present issues
>  further in the application...
>
>  My questions are:  1) is this analysis correct and 2)how can you
>  maintain a unique id for each cassette in this situation ... do you
> have
>  to assign a unique number for each cassette using some sort of CF
code
>  or is there a way to still utilize the DB's automatic unique id
>  assignment feature?   
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to