memory databases fail in Windows

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

memory databases fail in Windows

Mike Bonner via use-livecode
Hi all. I have a function that works in Mac but not in Windows. Here is the relevant code:

function arrayToMemoryDB aArrayData
   put the keys of aArrayData into tArrayKeys
   sort tArrayKeys numeric ascending
   put ":MEMORY:" into tDBFile
   
   try
      put revOpenDatabase("sqlite", tDBFile) into tDBID
     
      put "drop table arraydata" into tDropSQL
      revExecuteSQL tDBID, tDropSQL
      put  the result into tResult
   catch tError
      answer tError
      if the environment is "development" then exit to top else quit
   end try
<snip>

revOpenDatabase returns an error. Any idea why? It's a memory database! How can it NOT work??

Bob S


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
try changing :MEMORY: to :memory:

On Tue, Apr 3, 2018 at 11:38 AM, Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Hi all. I have a function that works in Mac but not in Windows. Here is
> the relevant code:
>
> function arrayToMemoryDB aArrayData
>    put the keys of aArrayData into tArrayKeys
>    sort tArrayKeys numeric ascending
>    put ":MEMORY:" into tDBFile
>
>    try
>       put revOpenDatabase("sqlite", tDBFile) into tDBID
>
>       put "drop table arraydata" into tDropSQL
>       revExecuteSQL tDBID, tDropSQL
>       put  the result into tResult
>    catch tError
>       answer tError
>       if the environment is "development" then exit to top else quit
>    end try
> <snip>
>
> revOpenDatabase returns an error. Any idea why? It's a memory database!
> How can it NOT work??
>
> Bob S
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
Ah! Curoius it works with Mac. I'll give that a try.

Bob S


> On Apr 3, 2018, at 11:12 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> try changing :MEMORY: to :memory:
>
> On Tue, Apr 3, 2018 at 11:38 AM, Bob Sneidar via use-livecode <
> [hidden email]> wrote:
>
>> Hi all. I have a function that works in Mac but not in Windows. Here is
>> the relevant code:
>>
>> function arrayToMemoryDB aArrayData
>>   put the keys of aArrayData into tArrayKeys
>>   sort tArrayKeys numeric ascending
>>   put ":MEMORY:" into tDBFile
>>
>>   try
>>      put revOpenDatabase("sqlite", tDBFile) into tDBID
>>
>>      put "drop table arraydata" into tDropSQL
>>      revExecuteSQL tDBID, tDropSQL
>>      put  the result into tResult
>>   catch tError
>>      answer tError
>>      if the environment is "development" then exit to top else quit
>>   end try
>> <snip>
>>
>> revOpenDatabase returns an error. Any idea why? It's a memory database!
>> How can it NOT work??
>>
>> Bob S
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
In reply to this post by Mike Bonner via use-livecode
Bob Sneidar wrote:

> Hi all. I have a function that works in Mac but not in Windows. Here is the relevant code:
>
> function arrayToMemoryDB aArrayData
>    put the keys of aArrayData into tArrayKeys
>    sort tArrayKeys numeric ascending
>    put ":MEMORY:" into tDBFile
>    
>    try
>       put revOpenDatabase("sqlite", tDBFile) into tDBID
>      
>       put "drop table arraydata" into tDropSQL
>       revExecuteSQL tDBID, tDropSQL
>       put  the result into tResult
>    catch tError
>       answer tError
>       if the environment is "development" then exit to top else quit
>    end try
> <snip>
>
> revOpenDatabase returns an error. Any idea why? It's a memory database! How can it NOT work??

What is the goal?

Arrays and memory-based SQLite are both in-memory stores with hashed
access.  I'm guessing there's something more to this use-case than my
limited thinking currently grasps.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
You would be correct. :-)

I posted a little while ago that I wrote some code to gather certain properties of all the objects on a card into an array. Converting that array into a memory database allows me to find all the objects that are for example, visible and groups and then get the top, left, bottom and right of each of these objects (because I passed those in a list to the thing that generates the array).

Essentially it's for finding things in an array. You might say I could do the same thing by iterating through all the elements of an array, but what if I wanted to do multiple queries? It's easier for me to write SQL queries than it is to code repeat loops.

Bob S


> On Apr 3, 2018, at 11:38 , Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> What is the goal?
>
> Arrays and memory-based SQLite are both in-memory stores with hashed access.  I'm guessing there's something more to this use-case than my limited thinking currently grasps.
>
> --
> Richard Gaskin


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
Bob Sneidar wrote:

 >> On Apr 3, 2018, at 11:38 , Richard Gaskin wrote:
 >>
 >> What is the goal?
 >>
 >> Arrays and memory-based SQLite are both in-memory stores with hashed
 >> access.  I'm guessing there's something more to this use-case than my
 >> limited thinking currently grasps.
 >
 > You would be correct. :-)
 >
 > I posted a little while ago that I wrote some code to gather certain
 > properties of all the objects on a card into an array. Converting that
 > array into a memory database allows me to find all the objects that
 > are for example, visible and groups and then get the top, left, bottom
 > and right of each of these objects (because I passed those in a list
 > to the thing that generates the array).
 >
 > Essentially it's for finding things in an array. You might say I could
 > do the same thing by iterating through all the elements of an array,
 > but what if I wanted to do multiple queries? It's easier for me to
 > write SQL queries than it is to code repeat loops.

I hear ya'.  I find myself tempted way more than I have time for to
write an xquery-like library for working with arrays.  We could sure use
one.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
Yes please!

###I hear ya'.  I find myself tempted way more than I have time for to
write an xquery-like library for working with arrays.  We could sure use
one.###



On Tue, Apr 3, 2018 at 2:12 PM, Richard Gaskin via use-livecode <
[hidden email]> wrote:

> Bob Sneidar wrote:
>
> >> On Apr 3, 2018, at 11:38 , Richard Gaskin wrote:
> >>
> >> What is the goal?
> >>
> >> Arrays and memory-based SQLite are both in-memory stores with hashed
> >> access.  I'm guessing there's something more to this use-case than my
> >> limited thinking currently grasps.
> >
> > You would be correct. :-)
> >
> > I posted a little while ago that I wrote some code to gather certain
> > properties of all the objects on a card into an array. Converting that
> > array into a memory database allows me to find all the objects that
> > are for example, visible and groups and then get the top, left, bottom
> > and right of each of these objects (because I passed those in a list
> > to the thing that generates the array).
> >
> > Essentially it's for finding things in an array. You might say I could
> > do the same thing by iterating through all the elements of an array,
> > but what if I wanted to do multiple queries? It's easier for me to
> > write SQL queries than it is to code repeat loops.
>
> I hear ya'.  I find myself tempted way more than I have time for to write
> an xquery-like library for working with arrays.  We could sure use one.
>
> --
>  Richard Gaskin
>  Fourth World Systems
>  Software Design and Development for the Desktop, Mobile, and the Web
>  ____________________________________________________________________
>  [hidden email]                http://www.FourthWorld.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: memory databases fail in Windows

Mike Bonner via use-livecode
In reply to this post by Mike Bonner via use-livecode
Enjoy! If you make it better post updates. Eventually we can put it into the library we all share. I use it for querying for the min top and left, and the max bottom and right of all visible objects on a card. But it can be used In a lot of ways. You could store data in an array in a stack property, convert it to a memory db at runtime, then convert it back whenever you want to "commit" the changes. None of the data ever touches the disk in a way that something outside Livecode could access. I suppose now I will have to write memoryDBToArray()

function arrayToMemoryDB aArrayData
   put the keys of aArrayData into tArrayKeys
   sort tArrayKeys numeric ascending
   put ":memory:" into tDBFile
   
   try
      put revOpenDatabase("sqlite", tDBFile) into tDBID
     
      if "Error" is in tDBID then
         throw tDBID
         return empty
      end if
     
      put "drop table arraydata" into tDropSQL
      revExecuteSQL tDBID, tDropSQL
      put  the result into tResult
   catch tError
      answer tError
      if the environment is "development" then exit to top else quit
   end try
   
   -- create the table
   put "create table" && quote & "arraydata" & quote \
         & cr into tCreateCommand
   put "(" & quote & "recordid" & quote && "NUMERIC PRIMARY KEY NOT NULL UNIQUE, " \
         & cr after tCreateCommand
   
   put the keys of aArrayData [1] into tRecordKeyList
   
   repeat for each line tRecordKey in tRecordKeyList
      put quote & tRecordKey & quote && "VARCHAR, " & cr after tCreateCommand
   end repeat
   
   delete char -3 to -1 of tCreateCommand
   put ")" after tCreateCommand
   
   try
      revExecuteSQL tDBID, tCreateCommand
      put the result into tResult
      if tResult is not 0 then breakpoint
   catch tError
      breakpoint
   end try
   
   -- insert data
   repeat for each line tKey in tArrayKeys
      put aArrayData [tKey] into aRecordData
      put 1 into tCounter
      put "recordid" into item tCounter of tColumns
      put ":" & tCounter into item tCounter of tColumnData
      put tKey into aColumnData [tCounter]
     
      repeat for each line tRecordKey in tRecordKeyList
         add 1 to tCounter
         put tRecordKey into item tCounter of tColumns
         put ":" & tCounter into item tCounter of tColumnData
         put aRecordData [tRecordKey] into aColumnData [tCounter]
      end repeat
     
      put "(" & tColumns & ")" into tColumns
      put "(" & tColumnData & ")" into tColumnData
      put "insert into arraydata" && tColumns && "VALUES" && tColumnData into tInsertSQL
      replace quote with "\" & quote in tInsertSQL
      replace "'" with quote in tInsertSQL
     
      try
         revExecuteSQL tDBID, tInsertSQL, "aColumnData"
         put the result into tResult
         if tResult is not 1 then breakpoint
      catch tError
         breakpoint
      end try
   end repeat
   
   return tDBID
end arrayToMemoryDB



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode