New topic: Storing a multi-dimensional array in a database.
<http://forums.realsoftware.com/viewtopic.php?t=45153> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message Farflame Post subject: Storing a multi-dimensional array in a database.Posted: Tue Aug 28, 2012 11:29 am Joined: Tue Oct 05, 2010 6:25 am Posts: 172 I can't quite get my head around this one, it feels like there should be a simple solution. Say I want to store MyArray(100,100,10) (integers) in a database. Two ways I can think of, one is to make the array into a big string and just store it as a single string. That would work for my current example (although I can't find the command in RB to make a string from an array... is there a command or will I have to join it together in a loop?). The other, which I think is wrong, is to do the loop and put each individual array into the database seperately (with the commit after the loop). This seems better if I wanted to read and store individual elements later. But this just sounds wrong and I have a feeling there's a more elegant solution - after all, isn't this sort of thing that databases are designed for? Have to admit, database structures just haven't clicked in my head yet. Top npalardy Post subject: Re: Storing a multi-dimensional array in a database.Posted: Tue Aug 28, 2012 11:40 am Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7383 Location: Canada, Alberta, Near Red Deer Farflame wrote:I can't quite get my head around this one, it feels like there should be a simple solution. Say I want to store MyArray(100,100,10) (integers) in a database. Two ways I can think of, one is to make the array into a big string and just store it as a single string. That would work for my current example (although I can't find the command in RB to make a string from an array... is there a command or will I have to join it together in a loop?). The other, which I think is wrong, is to do the loop and put each individual array into the database seperately (with the commit after the loop). This seems better if I wanted to read and store individual elements later. But this just sounds wrong and I have a feeling there's a more elegant solution - after all, isn't this sort of thing that databases are designed for? Have to admit, database structures just haven't clicked in my head yet. Most DB's have no way to store an array directly so you have to design a table to do that. Personally I would simply store the two indexes & the value in a table with at least 3 columns (assuming you only want to store one array) Then you can make the array as big as you want in 2 dimensions and the code to load it / save it really won't have to change If you want to store several & "name" them then you need a little more like an extra column for the "name" - but this isn't the best design as you repeat the name over & over. _________________ My web site Great White Software RBLibrary.com REALbasic learning Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
