Offline(local) "database" storage in LANSA Mobile

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
dhnaigles
Posts: 43
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Offline(local) "database" storage in LANSA Mobile

Post by dhnaigles » Sat Mar 03, 2018 4:59 am

Does anyone have any ideas about storing database records locally in LANSA Mobile. LongRange had the ability to create and maintain local database objects and records, but this does not seem to be available in LANSA Mobile Web Pages. I have a VL Web Page that stores data, that has been changed while offline, using collections, but if the user closes the page all of this data is gone. I need to be able to store the data in Local Storage or a Local database so that is can be available the next time the user opens the page. IDEAS?
David

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Offline(local) "database" storage in LANSA Mobile

Post by Stewart Marshall » Mon Mar 05, 2018 7:46 am

Hi David

Have a look at the VL LocalStorage implementation http://docs.lansa.com/14/en/lansa016/pr ... torage.htm

Best is probably to store the data as JSON (http://docs.lansa.com/14/en/lansa016/prim_web.json.htm)

Regards
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

dhnaigles
Posts: 43
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: Offline(local) "database" storage in LANSA Mobile

Post by dhnaigles » Tue Mar 06, 2018 2:56 am

Stewart,
I am already using LocalStorage for much of my data, but I have BLOB data (Signatures and Camera Photos) which needs to be stored in there. Will PRIM_WEB.Json allow the use of BLOB fields to be stored in the array or collection?

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Offline(local) "database" storage in LANSA Mobile

Post by Stewart Marshall » Tue Mar 06, 2018 1:34 pm

LocalStorage is very limited in size. Typically 5-10Mb per domain if I recall, so storing images is a problem.

If the app is available via the LANSA mobile wrapper, I think you can access the stored images using the xDevice* components.

Might be wrong though. Getting a little rusty these days.
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

GregSippel
Posts: 25
Joined: Thu May 19, 2016 11:34 am

Re: Offline(local) "database" storage in LANSA Mobile

Post by GregSippel » Tue Mar 06, 2018 3:27 pm

Stewart, your memory is still good !!

David, if you are using the LANSA mobile container try the xDeviceFileWrite and xDeviceFileRead widgets.

Cheers
Greg

VLNinja70

Re: Offline(local) "database" storage in LANSA Mobile

Post by VLNinja70 » Tue Mar 06, 2018 6:20 pm

There is also Indexed DB, seems to be a growing way of storing offline data.
Thats how Google is doing it with thier Progressive web apps
https://developers.google.com/web/funda ... ne-for-pwa

Size limits depending on what you are running on, more than positive the quotas can be overwritten
https://www.html5rocks.com/en/tutorials ... -research/

This guy claims to have gotten 2.0+ GB on Fire fox before it crashed
https://www.raymondcamden.com/2015/04/1 ... and-limits

More details about it
https://developer.mozilla.org/en-US/doc ... _IndexedDB

dhnaigles
Posts: 43
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: Offline(local) "database" storage in LANSA Mobile

Post by dhnaigles » Tue Mar 06, 2018 11:53 pm

Greg
I looked at the xFileRead and Write, but there is no documentation other than the widgets themselves. Do you, or anyone, have a little sample code for how to implement the widget?

GregSippel
Posts: 25
Joined: Thu May 19, 2016 11:34 am

Re: Offline(local) "database" storage in LANSA Mobile

Post by GregSippel » Wed Mar 07, 2018 9:21 am

David,

Sorry, I don't have a sample. However, its usage is similar to the other xDevice widgets that do have samples such as camera and audio. From looking at the Implementation tab of the widget and reading its source code it usage looks fairly easy. For write,

1) Set the Filename, FileType, FileEncoding, DataEncoding and Data properties.
2) Then invoke the write method
3) The complete event can then be listened for to tell what the status and returned message is

Then to read simply do the same, expect the method is"Read" and the data is returned via the completed event.

Cheers
Greg

JamesDuignan
Posts: 56
Joined: Thu Nov 26, 2015 1:43 pm

Re: Offline(local) "database" storage in LANSA Mobile

Post by JamesDuignan » Thu Mar 08, 2018 10:22 am

Hi David,

Here is an example of a reusable part i use as a wrapper for the file read widget widget to turn it into base64.

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT)

Code: Select all

* Widget

Define_Com Class(#xDeviceFileRead) Name(#GetBase64)

* Events

Define_Evt Name(Completed)
Define_Map For(*INPUT) Class(#prim_alph) Name(#Data)
Define_Map For(*INPUT) Class(#prim_alph) Name(#Status)
Define_Map For(*INPUT) Class(#prim_alph) Name(#Message)

*
* Event Routine
*

Evtroutine Handling(#GetBase64.Completed) Data(#Data) Message(#Message) Status(#Status)

Signal Event(Completed) Data(#Data) Message(#Message) Status(#Status)

Endroutine

*
* Method Routine
*

Mthroutine Name(GetFileBase64)
Define_Map For(*INPUT) Class(#PRIM_ALPH) Name(#FilePath)

#GetBase64.FileName := #FilePath

#GetBase64.FileType := BIN

#GetBase64.DataEncoding := BASE64

#GetBase64.Read

Endroutine

End_Com

you should Simply be able to make the call to the method GetFileBase64 and then the completed event will return you the data.

Regards,
James

dhnaigles
Posts: 43
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: Offline(local) "database" storage in LANSA Mobile

Post by dhnaigles » Fri Mar 09, 2018 12:44 am

Thank you very much, James. You are a credit to your father!

User avatar
MarcusLancaster
Posts: 22
Joined: Tue Nov 24, 2015 9:20 pm

Re: Offline(local) "database" storage in LANSA Mobile

Post by MarcusLancaster » Wed Nov 14, 2018 9:53 pm

Is there a way to "list" files which have been written to a device using write widget? I can write, read back and delete if I know the file name... but I wonder if there is a way to list contents?

dhnaigles
Posts: 43
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: Offline(local) "database" storage in LANSA Mobile

Post by dhnaigles » Wed Nov 14, 2018 11:31 pm

Marcus
I use localStorage and have the key start with a particular value. Here is my code for storing and retrieving images:
Mthroutine Name(GetBlobData)
Define_Map For(*INPUT) Class(#Signature) Name(#SaveSig)
Define Field(#sigFileName) Type(*STRING)
#DELLOC := #sys_web.LocalStorage<Location>.Value.AsNumber
#DELRTE := #sys_web.LocalStorage<DeliveryRoute>.Value.AsNumber
#DELDTE := #sys_web.LocalStorage<DeliveryDate>.Value.AsNumber
#DELSEQ := #sys_web.LocalStorage<CurrentSeq>.Value.AsNumber
#DELACTDTE := #STD_DATEX.now.AsNumber( YYMMDD )
#DELTIME := #STD_TIMX.now.AsNumber( HHMMSS )
#sigFileName := 'SIG' + #DELLOC.AsDisplayString( NumString_L ) + #DELDTE.AsString + #DELRTE.AsDisplayString( NumString_L ) + #DELSEQ.AsDisplayString( NumString_L ) + #DELTIME.AsDisplayString( NumString_L ) + #DELACTDTE.AsDisplayString( NumString_L )
#BlobReader.Read Blob(#SaveSig)
Endroutine
Evtroutine Handling(#BlobReader.Completed) Data(#Data)
If Cond(#sys_web.LocalStorage<#sigFileName> *Is *NULL)
#sys_web.LocalStorage.Add( #sigFileName, #data )
Endif
Endroutine
/* Send Saved Signatures to Server */
Mthroutine Name(SyncSignatures)
Define_Com Class(#srvPOD.UpdateSignatures) Name(#SendSigs)
Def_List Name(#sigsToDelete) Fields(#sigFileName) Type(*WORKING) Entrys(*MAX)
Def_List Name(#signatures) Fields(#sigFileName #DX_ELBLOB) Type(*WORKING) Entrys(*MAX)
Clr_List Named(#signatures)
Clr_List Named(#sigsToDelete)
For Each(#stg) In(#SYS_WEB.LocalStorage)
If Cond(#sys_web.LocalStorage<#sigFileName> *Is *NULL)
#sys_web.LocalStorage.remove( #sigFileName )
Endif
If Cond(#stg.Name.LeftMost( 3 ) = "SIG")
#data64 := #stg.Value
#sigFileName := #stg.Name
#DX_ELBLOB := #sys_web.CreateBlob( #data64 "image/jpeg" )
Add_Entry To_List(#signatures)
Endif
Endfor
#SendSigs.ExecuteAsync Signatures(#signatures) Sigstodelete(#sigsToDelete)
Evtroutine Handling(#SendSigs.Completed)
Selectlist Named(#sigsToDelete)
If Cond(#sys_web.LocalStorage<#sigFileName> *IsNot *NULL)
#sys_web.LocalStorage.remove( #sigFileName )
Endif
Endselect
Endroutine
Evtroutine Handling(#SendSigs.Failed) Handled(#handled)
#handled := True
Endroutine
Endroutine

User avatar
MarcusLancaster
Posts: 22
Joined: Tue Nov 24, 2015 9:20 pm

Re: Offline(local) "database" storage in LANSA Mobile

Post by MarcusLancaster » Thu Nov 15, 2018 1:56 am

Hi David

Brilliant - thanks for this - yep I'm also using a specific "root" name for the local storage entries so I can pick them up at a later time... its good to know I'm thinking along the right lines.

I just wanted to make sure that there wasn't a "xDeviceDirList" floating around somewhere that I was missing :-)

Cheers!

Marcus.

Post Reply