0

Ok so I have a name, a time/data, and an array...

so in my database I store in the table, the:

name, time/data, but the array?

This array doesn't have a fixed size... It is an array of tuples (x,y) <- even thats an array

I want to associate the name and time/date with this array. I heard its not good and impossible to store an array in a database, I'm using sqllite3..

How do I solve this problem? Do I just let the name and timedate table point to a newly constructed table for the array?

user3043594
  • 166
  • 10
  • 1
    You would probably want to use another table then do a join. Its called a 1 to many relationship. http://stackoverflow.com/questions/12402422/how-to-store-a-one-to-many-relation-in-my-sql-database-mysql – Coin_op Jan 23 '14 at 02:17

1 Answers1

1

Just create a table with X, Y, timestamp and a foreignkey to an entry in an entry table.

Data table:

ID  | Index |  X  |  Y  |  EntryID
0   |   0   | 3.2 | 4.3 |   1
1   |   1   | 2.1 | 1.2 |   1
........
n-1 |   n-1 | xn  | yn  |   1

# The above is from array 1, below from another array

n   |   0   | 2.2 | 2.4 |   2
n+1 |   1   | 2.1 | 1.9 |   2
.........
n+m-1 | m-1 | xm  | ym  |   2

Entry table:

ID | Name          | DateTime
1  | user3043594   | 2013-..
2  | Steinar Lima  | 2012-..

You store all entries from all arrays in this table, and filter them based on entry id. Then you can do a join to get the user name from the user table.

Steinar Lima
  • 7,644
  • 2
  • 39
  • 40
  • 1
    wait, I think you missed it! It is an array of ((x1,y1),(x2,y2)... (xn,yn)). Do you mind making an edit for that? – user3043594 Jan 23 '14 at 02:19
  • No, just save all tuples as a row in this table. So X1 goes in column X in row 1, Y1 in column Y in row 1.. etc. You may want to add an index column to the table, to keep track of the index in the array. I'll update my answer. – Steinar Lima Jan 23 '14 at 02:21
  • wait. its like this name, date time, ((x1,y1),(x2,y2)... (xn,yn)).. Don't I want to link it to another table with a row thats n long? or is this the one to many thing someone else mentioned? – user3043594 Jan 23 '14 at 02:25
  • With my solution you would have to repeat DateTime for each row, I'll update the answer. – Steinar Lima Jan 23 '14 at 02:31
  • 2
    Given that you don't understand the concept of one to many relationships, I've heard good things about the book, Database Design for Mere Mortals. – Dan Bracuk Jan 23 '14 at 02:32
  • Thank you Dan Bracuk! Thank you Steinar Lima! – user3043594 Jan 23 '14 at 02:35