Android Question [Discontinued] Dropbox-Sync-Library Reloaded - BETA-release

DonManfred

Expert
Licensed User
Longtime User
This Library is Discontinued as by 2.4.2015


This thread is a open betatest of a new Version of the Dropbox-Sync-Library.
This new Version will allow you to use Dropbox´s Datastores too.
You can find the Dropbox Api documentation here.

You can download the Library-files from my Dropbox-Account here. Examples will follow today too.

Actual Version shared: 3.29 (Library_3.29.rar)
This uses the most up to date Dropbox-SDK 3.1.2

Example 1: (Attached to this post)
This Example Loads a shareable Datastore and when you click on the MenuItem "Copy customers from DB to DS" Parts of the Northwind-Database (SQLite-DB, included in Assets) will be copied into the Datastore. Including BLOBs.
After the Data is inserted you can click on a table to show its content.
When viewing Employees and Categories the content is shown in a ListView (TwoLinesandBitmap)






To use the DropboxSync-Library (and the Datastores) you need to follow Erels Tutorial about the library first. When you setup everything correctly than you can have a look at the new Methods of the DbxAccountManager and the other new objects like DbxDatastore, DbxTable, DbxRecord... You will find more Informations about each object in the next posts.

But let´s start with the additions to the already know DbxAccountManager.

B4X:
manager.hasLinkedAccount
Results true or false. It the app is not linked to an Dropboxaccount then it will be false
If the app is linked (passed the authorization) then this will show true

example:
B4X:
Log("HasLinkedAccount="&manager.hasLinkedAccount)

B4X:
manager.GetLinkedAccounts
Gets a list of all linked Accounts (it can be more than one)
example:
B4X:
Dim acclist As List=manager.GetLinkedAccounts

B4X:
manager.GetAccount
Returns some Infos about the linked Account (Username, Organisationname and Displayname
example:
B4X:
Dim dbxacc As Map = manager.GetAccount

B4X:
manager.ListDatastores
Returns a list of all accessible Datastores

Example:
B4X:
Dim dslist As List = manager.ListDatastores
Log("dslistsize="&dslist.Size)
For i = 0 To dslist.Size -1
    Log(dslist.Get(i))
Next

B4X:
manager.deleteDatastore(<dsid>)
Deletes the Datastore with the given ID

Example:
B4X:
manager.deleteDatastore(".Q6k45pfVTNzrHnP4982XlPAm9v15Fzc0p225LS6mkhQ")


B4X:
manager.getDatastore(<dsid>)
Get the Datastore with the given ID
A Datastore (in b4a) is an Instance of an Object of Type DbxDatastore

example:
B4X:
DIM ds as DbxDatastore = manager.getDatastore(".KhR8uRUPUH963GBbcPvn5_RFH3Vp1XKq2pAqZtwynq4")

B4X:
manager.openOrCreateDatastore(<dsid>)

Creates a PRIVATE Datastore with the given ID.
Private Datastores are not shareable. The are for your own app only.

example
B4X:
Dim ds As DbxDatastore = manager.openOrCreateDatastore(".KhR8uRUPUH963GBbcPvn5_RFH3Vp1XKq2pAqZtwynq4")


B4X:
manager.createDatastore(shareds As boolean)
Creates a shareable Datastore. The ID is autocalculated in this case.
THIS is probably the type of Datastore you want to have/use!
If shareds is set to true then the Datastore will become a Principal = PUBLIC and a Role = EDITOR
If shareds is set to false then the defaults from Dropbox will apply.

example:
B4X:
Dim ds As DbxDatastore = manager.createDatastore(true)

In relation to SqLite for example we can say:
- A Datastore is likely a Database. It can hold any number of Tables. Each table can hold any number of Records (Object DbxRecord). Each record can hold any number of fields as the Datastores does not have a scheme like oridinary Databasesystems.
- A Record is like in normal Databases a "record" of one Table.

Edit
Autogenerated docs made with xml2bb script from @warwound

DropboxSync
Version:
3.29
  • DbxAccountManager
    Events:
    • AccountReady (Success As Boolean)
    • DatastoreDeleted (Success As Boolean)
    • DownloadCompleted (Success As Boolean, LocalDir As String, LocalFileName As String)
    • SyncCompleted (Success As Boolean)
    • onAccountChange (acc As Object)
    • onLinkedAccountChange (mgr as Object As , acc As Object)
    Fields:
    • AutoSync As Boolean
      If True then the cache will be synchronized automatically when a file is downloaded to assure that the latest file is downloaded.
    Methods:
    • DownloadFile (RemoteDir As String, RemoteFile As String, LocalDir As String, LocalFile As String)
      Downloads a file. If the file is not already in the cache then it will be automatically downloaded.
      The DownloadComplete event will be raised when the local file is ready.
      RemoteDir / RemoteFile - Remote path. The root folder (which is the app folder) is "/".
      LocalDir / LocalFile - The local file.
    • GetAccount As Map
    • GetLinkedAccount As DbxAccount
    • GetLinkedAccounts As List
    • Initialize (AppKey As String, AppSecret As String, EventName As String, setdebug As Boolean)
      Initializes the object.
      AppKey - The app key from Dropbox developer console.
      AppSecret - The app secret from Dropbox developer console.
      EventName - Sets the subs that will handle the events.
    • InitializeDatastoreManager
    • LinkAccount
      Links the application with the user's Dropbox account.
      If the account was not linked before then the user will be shown an authentication form.
      The AccountReady event will be raised when the account is ready.
    • ListDatastores As List
    • ListFiles (Dir As String) As List
      Returns a List with the infos of the files and folders under the given path.
      Each item in the list is a DbxFileInfo object.
    • Sync
      Forces a check for new file info from the server. The SyncCompleted event will be raised when the sync is completed.
    • UnlinkAccount
      Unlinks the application from the user's Dropbox account.
    • UploadFile (LocalDir As String, LocalFile As String, RemoteDir As String, RemoteFile As String)
      Writes a file to the local Dropbox cache. The file will be automatically uploaded to the Dropbox account.
      LocalDir / LocalFile - Path to the local file.
      RemoteDir / RemoteFile - Remote path. The root folder (which is the app folder) is "/".

      No event is raised after this action.
    • addListener (EventName As String)
    • createDatastore (shareDS As Boolean) As DbxDatastore
    • delete (Dir As String, FileName As String)
    • deleteDatastore (dsid As String)
    • getDatastore (dsid As String) As DbxDatastore

      Return type: @return:the Datastore with the ID dsid
    • hasLinkedAccount As Boolean
    • openDatastore (id As String) As DbxDatastore
    • openOrCreateDatastore (id As String) As DbxDatastore
      Opens the datastore with the given ID, creating it if it does not already exist.
      Datastores can be created offline with this method, and their contents will be
      merged with any datastore of the same name when the app is online again.
      The same datastore can't be opened more than once. You should generally keep
      a datastore open only when your the relevant part of app is on the screen, to
      maximize battery life.
      You must call DbxDatastore.close() when you are finished with a Datastore.
      See DbxDatastore.isValidId() for a description of valid strings for a datastore ID.
      Throws
      DbxException
      if there is a failure opening the datastore.
    • setDebug (debug As Boolean) As Boolean

      debug: the debug to set
    • stopListening
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.INTERNET
    Properties:
    • Debug As Boolean [read only]
    • FileSystem As DbxFileSystem [read only]
  • DbxDatastore
    Events:
    • onstatuschange (ds As DbxDatastore)
    Methods:
    • BASE_CHANGE_SIZE As Long
    • BASE_DATASTORE_SIZE As Long
    • BASE_UNSYNCED_CHANGES_SIZE As Long
    • Close
    • DATASTORE_SIZE_LIMIT As Long
    • GetEffectiveRole As Role
    • IsInitialized As Boolean
    • ListTables As List

      Return type: @return:
    • RECORD_COUNT_LIMIT As Long
    • Sync As Map
    • UNSYNCED_CHANGES_SIZE_LIMIT As Long
    • getTable (id As String) As DbxTable

      Return type: @return:
    • isOpen As Boolean
      Returns whether this DbxDatastore is currently open (i.e. it has not been closed).
    • isShareable As Boolean
      Returns whether this DbxDatastore can be shared with other users. (This is currently equivalent to whether the ID starts with ".".)
      Return type: @return:
    • isWriteable As Boolean
      Returns whether this DbxDatastore is writable by the current user. (This is currently equivalent to whether the role is EDITOR or OWNER.)
    • setrole (principal As String, dsrole As String)
    • startListening (EventName As String)
    • stopListening
    Properties:
    • ID As String [read only]
      gets the id of this Datastore
    • Mtime As Date [read only]
    • RecordCount As Long [read only]
      getRecordCount
    • Size As Long [read only]
      gets the size
    • SyncStatus As DbxDatastoreStatus [read only]
    • Title As String
      Returns the title of this datastore.
  • DbxDatastoreStatus
    Methods:
    • IsInitialized As Boolean
    • hasIncoming As Boolean
      Set when there are remote changes that will be incorporated by the next call to DbxDatastore.sync().
    • hasOutgoing As Boolean
      Set when there are local changes that haven't yet been committed by a call to DbxDatastore.sync().
    • isConnected As Boolean
      Set when the API is in active communication with the server, so that remote changes are likely to be visible quickly, and local changes can be uploaded soon. The API will attempt to connect when datastores are open, but may fail if offline.
    • isDownloading As Boolean
      Set when there are remote changes that need to be downloaded from the server. Always set when a DbxDatastore is opened until the first successful check for updates. Always set for a local datastore.
    • isUploading As Boolean
      Set when there are local changes that need to be uploaded to the server. Always set for a local datastore that has any changes at all.
    • needsReset As Boolean
      Set when the datastore needs to be reset with a call to DbxDatastore.close() followed by DbxDatastoreManager.uncacheDatastore().
  • DbxFields
    Methods:
    • Fieldnames As List
    • Initialize As DbxFields
      getRecord delete field name
    • IsInitialized As Boolean
    • deleteField (name As String) As DbxRecord
    • getBoolean (name As String) As Boolean
      Returns the Boolean "name".
    • getBytes (name As String) As Byte[]
      Returns the Bytes "name".
    • getDate (name As String) As Long
      Returns the Date "name".
    • getDouble (name As String) As Double
      Returns the Double "name".
    • getFieldType (name As String) As ValueType
      Returns the Double "name".
    • getId (o As Object) As Boolean
    • getList (name As String) As DbxList
      Returns the List "name".
    • getLong (name As String) As Long
      Returns the Long "name".
    • getOrCreateList (name As String) As DbxList
      Returns the Long "name".
    • getString (name As String) As String
      Returns the String "name".
    • getTitle (name As String) As String
    • hasField (name As String) As Boolean
      Returns
    • hashCode As Int
      Returns
    • isValidFieldName (name As String) As Boolean
    • setBoolean (name As String, value As Boolean) As DbxFields
      Returns
    • setByte (name As String, value() As Byte) As DbxFields
      Returns
    • setDate (name As String, value As Long) As DbxFields
      Returns
    • setDouble (name As String, value As Double) As DbxFields
      Returns
    • setFields (fields As DbxFields) As DbxFields
      Returns
    • setList (name As String, value As DbxList) As DbxFields
      Returns
    • setLong (name As String, value As Long) As DbxFields
      Returns
    • setString (name As String, value As String) As DbxFields
      Returns
  • DbxFileInfo
    Methods:
    • IsInitialized As Boolean
    Properties:
    • IsFolder As Boolean [read only]
      Tests whether this is a folder.
    • ModifiedTime As Long [read only]
      Returns the last modified time based on the local device system clock.
    • Name As String [read only]
      Returns the file or folder name.
    • Path As DbxPath [read only]
    • Size As Long [read only]
      Returns the file size in bytes.
  • DbxFileSystem
    Events:
    • onPathChange (Path As DbxPath, m As Mode)
    Methods:
    • GetModes As List
    • IsInitialized As Boolean
    • addPathListener (EventName As String, path As String, m As String)
    • stopPathListening (path As DbxPath, mode As Mode)
  • DbxList
    Methods:
    • IsInitialized As Boolean
    • addBoolean (elem As Boolean) As DbxList
      Adds the given boolean value, appending it to the end of the list. Returns a
      reference to this object, to allow for call chaining.
      elem:
      Return type: @return:
    • addBooleanAt (index As Int, elem As Boolean) As DbxList
      Adds the given boolean value, inserting it at the given
      index in the list. Returns a reference to this object,
      to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • addByte (elem() As Byte) As DbxList
      Adds the given byte value, appending it to the end of the list.
      The value must not be null. Returns a reference to this object,
      to allow for call chaining.
      elem:
      Return type: @return:
    • addByteAt (index As Int, elem() As Byte) As DbxList
      Adds the given byte value, inserting it at the given
      index in the list. The value must not be null. Returns
      a reference to this object, to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • addDate (elem As Long) As DbxList
      Adds the given Date value, appending it to the end of the
      list. The value must not be null. Returns a reference to
      this object, to allow for call chaining.
      elem:
      Return type: @return:
    • addDateAt (index As Int, elem As Long) As DbxList
      Adds the given Date value, inserting it at the given
      index in the list. The value must not be null. Returns
      a reference to this object, to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • addDouble (elem As Double) As DbxList
      Adds the given double value, appending it to the end of the list. Returns a
      reference to this object, to allow for call chaining.
      elem:
      Return type: @return:
    • addDoubleAt (index As Int, elem As Double) As DbxList
      Adds the given double value, inserting it at the given
      index in the list. Returns a reference to this object,
      to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • addLong (elem As Long) As DbxList
      Adds the given long value, appending it to the end of the list. Returns a
      reference to this object, to allow for call chaining.
      elem:
      Return type: @return:
    • addLongAt (index As Int, elem As Long) As DbxList
      Adds the given long value, inserting it at the given
      index in the list. Returns a reference to this object,
      to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • addString (elem As String) As DbxList
      Adds the given String value, appending it to the end of the list. The value
      must not be null. Returns a reference to this object, to allow for call chaining.
      elem:
      Return type: @return:
    • addStringAt (index As Int, elem As String) As DbxList
      Adds the given String value, inserting it at the given
      index in the list. The value must not be null.Returns
      a reference to this object, to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • clear As DbxList
      Deletes all elements from this list.
      This operation will override any parallel
      changes rather than merging with them.
    • equals (elem As DbxList) As Boolean
    • getBoolean (index As Int) As Boolean
      Returns the value of a boolean element at the given index, which must exist and be of the correct type.
      index:
    • getBytes (index As Int) As Byte[]
      Returns the value of a byte element at the given index, which must exist and be of the correct type.
      index:
    • getDate (index As Int) As Long
      Returns the value of a Date element at the given index, which must exist and be of the correct type.
      index:
    • getDouble (index As Int) As Double
      Returns the value of a double element at the given index, which must exist and be of a numerical type.
      If the field value is a long, this method will silently convert it to a double. No conversion is
      performed on other field types.
      index:
    • getLong (index As Int) As Long
      Returns the value of a long element at the given index, which must exist and be of the correct type.
      This method won't convert a double or boolean field to a long.
      index:
    • getString (index As Int) As String
      Returns the value of a String element at the given index, which must exist and be of the correct type.
      index:
    • getType (index As Integer) As AtomType
      Returns the type of the element at the given index.
      index:
      Return type: @return:
    • hashCode As Int
    • isEmpty As Boolean
      Returns whether this list is empty.
      Return type: @return:
    • move (oldindex As Int, newindex As Int) As DbxList
      Moves the element at oldIndex (which must exist)
      to a position such that its index in the modified
      list will be newIndex. Returns a reference to
      this object, to allow for call chaining.
      oldindex:
      newindex:
      Return type: @return:
    • remove (index As Int) As DbxList
      Removes the element at the given index,
      which must exist. Returns a reference to
      this object, to allow for call chaining.
      index:
      Return type: @return:
    • setBooleanAt (index As Int, elem As String) As DbxList
      Replaces the element at the given index
      with a new boolean value. Returns a
      reference to this object, to allow for
      call chaining.
      index:
      elem:
      Return type: @return:
    • setByteAt (index As Int, elem() As Byte) As DbxList
      Replaces the element at the given index with a
      new String value. The value must not be null.
      Returns a reference to this object, to allow
      for call chaining.
      index:
      elem:
      Return type: @return:
    • setDateAt (index As Int, elem As Long) As DbxList
      Replaces the element at the given index with a
      new Date value. The value must not be null.
      Returns a reference to this object, to allow
      for call chaining.
      index:
      elem:
      Return type: @return:
    • setDoubleAt (index As Int, elem As Double) As DbxList
      Replaces the element at the given index with a
      new double value. Returns a reference to this
      object, to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • setLongAt (index As Int, elem As Long) As DbxList
      Replaces the element at the given index with
      a new long value. Returns a reference to this
      object, to allow for call chaining.
      index:
      elem:
      Return type: @return:
    • setStringAt (index As Int, elem As String) As DbxList
      Replaces the element at the given index with a
      new String value. The value must not be null.
      Returns a reference to this object, to allow
      for call chaining.
      index:
      elem:
      Return type: @return:
    • size As Int
      Returns the number of elements in this list.
      Return type: @return:integer
  • DbxPath
    Methods:
    • IsInitialized As Boolean
  • DbxRecord
    Methods:
    • IsInitialized As Boolean
    • asMap As Map
    • deleteRecord
    • fieldNames As List
    • getBoolean (name As String) As Boolean
      Returns the Boolean "name".
    • getBytes (name As String) As Byte[]
      Returns the Bytes "name".
    • getDate (name As String) As Date
      Returns the Date "name".
    • getDouble (name As String) As Double
      Returns the Double "name".
    • getFieldType (name As String) As ValueType
      Returns the Double "name".
    • getList (name As String) As DbxList
      Returns the List "name".
    • getLong (name As String) As Long
      Returns the Long "name".
    • getString (name As String) As String
      Returns the String "name".
    • hasField (name As String) As Boolean
      Returns
    • hashCode As Int
      Returns
    • isDeleted As Boolean
      Returns
    • setBoolean (name As String, value As Boolean) As DbxRecord
      Returns
    • setByte (name As String, value() As Byte) As DbxRecord
    • setDate (name As String, value As Long) As DbxRecord
    • setDouble (name As String, value As Double) As DbxRecord
    • setFields (fields As DbxFields) As DbxRecord
    • setList (name As String, value As DbxList) As DbxRecord
    • setLong (name As String, value As Long) As DbxRecord
    • setString (name As String, value As String) As DbxRecord
    Properties:
    • Id As String [read only]
      gets the ID
    • Size As Long [read only]
      Returns the Long "name".
  • DbxTable
    Methods:
    • Insert As DbxRecord
      getRecord with ID id
    • IsInitialized As Boolean
    • getOrInsert (id As String) As DbxRecord
    • query As QueryResult
    Properties:
    • Id As String [read only]
      gets the ID
  • QueryResult
    Methods:
    • GetAll As List
    • IsInitialized As Boolean
    • RecordCount As Integer
    • hasResults As Boolean
 

Attachments

  • DbxB4Aex1.zip
    425.5 KB · Views: 461
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Placeholder for future editings (1)

The object DbxDatastore

B4X:
Dim ds As DbxDatastore = manager.getDatastore(".KhR8uRUPUH963GBbcPvn5_RFH3Vp1XKq2pAqZtwynq4")
The Datastore can be treated like an sqlite-database. It´s the Database and it can hold any numbers of tables.

B4X:
ds.setrole(String principal, String dsrole)
Sets the Role and the Pricipal to a Datastore.
Principal can be one of the strings "PUBLIC" or "TEAM".
Role can be one of the strings "OWNER", "EDITOR", "VIEWER" or "NONE".
This will only work with a "shareable Datastore"!
Available in Library v3.30
B4X:
ds.isShareable()
Returns whether this DbxDatastore can be shared with other users. (This is currently equivalent to whether the ID starts with ".".)
Available in Library v3.30
B4X:
ds.isWriteable()
Returns whether this DbxDatastore is writable by the current user. (This is currently equivalent to whether the role is EDITOR or OWNER.)
Available in Library v3.30

B4X:
ds.ListTables
Returns a set of all tables in the datastore that currently contain any records.

Example:
B4X:
Dim tabellen As List = ds.ListTables
Log("Num Tables="&tabellen.Size)
For i = 0 To tabellen.Size-1
    Dim dsid As String = tabellen.Get(i)
    If dsid.StartsWith(":") Then
    Else
        Log(tabellen.Get(i))
    End If
Next

B4X:
ds.getTable("customers")
Get the Table with the given name from the Datastore. A Table in this case is a object of Type DbxTable.
The Table is a subset of an Datastore. The Table hold all Records which are in this Table.

Example:
B4X:
Dim t As DbxTable = ds.getTable("customers")

B4X:
ds.IsInitialized
Returns whether the Datastore is initialized or not.
B4X:
ds.Close
Closes this datastore, and ceases monitoring for updates. This must be called to release this datastore when you're finished with it.

Any changes you committed with a call to sync() are safe on disk, and will continue to upload in the background until the DbxDatastoreManager is shut down, after which they will remain queued until the next time you open this datastore. Any changes made since the last call to sync() will be discarded.


You must close a datastore when you're done using it to indicate to the Sync API that you are no longer interested in receiving updates for this datastore. After a call to this method, the Datastore can no longer be used and listeners will no longer be called. You must open the datastore again if you want to access it.

B4X:
ds.ID
Returns the ID of this Datastore
B4X:
ds.isOpen
Returns whether a Datastore is opened or not.
B4X:
ds.RecordCount
Returns the total number of records in this datastore.
B4X:
ds.Size
Returns the size of this datastore in bytes. The overall size of a datastore is calculated by summing the size of all records, plus the base size of an empty datastore itself.
B4X:
ds.Mtime
Returns the last modified time of this datastore, or null if no data has been synced yet.
The last modified time is automatically updated on each call to sync() which commits local changes, or incorporates remote changes. The timestamp is based on the local clock of the device where the change is made.

B4X:
ds.Sync
Sync the Datastore. This is probably the MOST used command when working with Datastores. Everytime when you edit a record, change a record or create a new record in a table... All changes are in memory first.... A call of ds.Sync will "submit" all changes to the Datastore. The Dropbox manager will then sync th datastore with the dropboxserver mixing all together.

Apply all outstanding changes to the datastore, and also incorporate remote changes into this datastore. This method does not wait for network I/O, but does wait for disk I/O. When this method returns, all local changes have been safely saved to disk, and will be uploaded in the background.

Returns a map from table IDs to sets of DbxRecords. These correspond to the tables and records that changed due to remote changes applied during this sync. Records deleted on the server will be included in the list, and you can call DbxRecord.isDeleted() to detect them. If nothing was changed remotely, the result is an empty map.
NOTE: This is actually missing in the library but it stands on the Todo list.

Throws
DbxException.NotFound
if the datastore was deleted on the server.


DbxException
if there is a problem updating local state.


B4X:
ds.Title
Gets or sets the Title of this Datastore

B4X:
ds.BASE_CHANGE_SIZE ' The size in bytes of a change before accounting for the size of its values.The overall size of a change is this value plus the size of the values in the change.
ds.BASE_DATASTORE_SIZE '  The size in bytes of a datastore before accounting for the size of its records. The overall size of a datastore is this value plus the size of all records.
ds.BASE_UNSYNCED_CHANGES_SIZE ' The size in bytes of unsynced changes before accounting for the size of each change.The overall size of unsynced changes is this value plus the size of each change.
ds.DATASTORE_SIZE_LIMIT ' The maximum size in bytes of a datastore.
ds.UNSYNCED_CHANGES_SIZE_LIMIT ' The maximum size in bytes of changes that can be queued up between calls to sync().
ds.RECORD_COUNT_LIMIT ' The maximum number of records in a datastore.

Some Informations about sizes and limits.
tbc
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The object DbxTable

B4X:
Dim t As DbxTable = ds.getTable("customers")

Todo: Documenting the properties and methods
B4X:
t.getOrInsert(<id>)
Get the DbxRecord with the given id. If the record is not found then it is created.
B4X:
t.Id
Get the id of this Table
B4X:
t.Insert
Insert a new Record in the Table and return the new created DbxRecord object
B4X:
t.IsInitialized
Returns whether the table is initialized or not
B4X:
t.query
Return all Records of this table as a QueryResult.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The object DbxRecord
The record is the smallest part of an Datastore.
Remember: A Datastore can hold any number of Tables. Each table can have its own Records

B4X:
Dim rec As DbxRecord = t.Insert()

ToDo: Documenting the properties and methods
B4X:
rec.asMap
Returns all fields of this record as a map. This is usually the most interesting method.
B4X:
rec.fieldNames
Returns a list with all Fieldnames of this record.
B4X:
rec.getBoolean(key As String)
Return a Boolean with the fieldname key
B4X:
rec.getBytes(key As String)
Return a byte[] with the fieldname key
B4X:
rec.getDate(key As String)
Return a Long with the fieldname key
B4X:
rec.getDouble(key As String)
Return a Double with the fieldname key
B4X:
rec.getFieldType(key As String)
Returns the Fieldtype of the field key
B4X:
rec.getList(key As String)
Return a List of type DbxList with the fieldname key
B4X:
rec.getLong(key As String)
Return a Long with the fieldname key
B4X:
rec.getString(key As String)
Return a String with the fieldname key
B4X:
rec.hasField(key As String)
Returns whether the record has the key or not
B4X:
rec.hashCode
Return the hash-code of this Record
B4X:
rec.Id
Return the records id
B4X:
rec.isDeleted
Return whether the record is deleted
B4X:
rec.isInitialized
Return whether the object is initialized
B4X:
rec.setBoolean(key As String, value as Boolean)
Sets the boolean value to the field with the name key
B4X:
rec.setBytes(key As String, value[] as Byte)
Sets the byte[] value to the field with the name key
B4X:
rec.setDate(key As String, value as Long)
Sets the Long value to the field with the name key
B4X:
rec.setDouble(key As String, value as Double)
Sets the Double value to the field with the name key
B4X:
rec.setFields(value as DbxFields)
Sets the fields value to the record
B4X:
rec.setList(key As String, value as DbxList)
Sets the List value to the field with the name key
B4X:
rec.setLong(key As String, value as Long)
Sets the Long value to the field with the name key
B4X:
rec.setString(key As String, value as String)
Sets the string value to the field with the name key
B4X:
rec.Size
Returns the size of this record
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The object DbxList
ToDo: Documenting the methods
B4X:
Dim l As DbxList
l.addBoolean
l.addBooleanAt
l.addByte
l.addByteAt
l.addDate
l.addDateAt
l.addDouble
l.addDoubleAt
l.addLong
l.addLongAt
l.clear
l.equals
l.GetType
l.hashCode
l.IsInitialized
l.setBooleanAt
l.setByteAt
l.setDateAt
l.setDoubleAt
l.setLongAt
l.setStringAt
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The object QueryResult

The QueryResult is a list of all Records (DbxRecord) which is returned by a query-call in a table
B4X:
Dim res As QueryResult = t.query
Dim l As List = res.GetAll
Log("SizeOfCustomers="&l.Size)
datastore.Clear
For i = 0 To l.Size -1
    Dim rec As DbxRecord  = l.Get(i)
    Log("Map="&rec.asMap)
Next
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but I wonder if this post won't be better put in the Library thread instead of the Question one
The library will be published here, yes. BUT it is still a BETA-Release (not for production) and i asked erel what to do. I mean; where to discuss this betatest. I thought about a private message with all testers. But in private messages you are not allowed to upload attachments.
So i asked Erel
I think that a single thread in the questions forum should be the best place to discuss it.

Here is am. THIS is the thread i will use for my Betatest :)

When the libary is fit to get an RC-status then i will Post the library in the Librarysection too. For sure.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The object DbxDatastoreStatus hold some Sync-Informations about the Datastore.
You can get the Datastore-Sync-Status by calling

B4X:
Dim dsstatus as DbxDatastoreStatus = ds.getSyncStatus

B4X:
dsstatus.hasIncoming
Set when there are remote changes that will be incorporated by the next call to DbxDatastore.sync().
B4X:
dsstatus.hasOutgoing
Set when there are local changes that haven't yet been committed by a call to DbxDatastore.sync().
B4X:
dsstatus.isConnected
Set when the API is in active communication with the server, so that remote changes are likely to be visible quickly, and local changes can be uploaded soon. The API will attempt to connect when datastores are open, but may fail if offline.
B4X:
dsstatus.isDownloading
Set when there are remote changes that need to be downloaded from the server. Always set when a DbxDatastore is opened until the first successful check for updates. Always set for a local datastore.
B4X:
dsstatus.IsInitialized
B4X:
dsstatus.isUploading
Set when there are local changes that need to be uploaded to the server. Always set for a local datastore that has any changes at all.
B4X:
dsstatus.needsReset
Set when the datastore needs to be reset with a call to DbxDatastore.close() followed by DbxDatastoreManager.uncacheDatastore().
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Start betatest now :D
The first post is updated and a link to download is inserted.
As to the size of the files i have shared it on my Dropbox

Example will follow later today. I´ll look out to create an suiteable example to convert exiting data into a Datastore.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
A few minutes ago i got a BADLY DAMN importantly note about my problem with the newest SDK 3.1.2 which are needed to Share a Datastore... I forgot to copy the native libs (.so)!!!

I´m working on trying the new SDK actually. Will update the files when i think it works later.

THANK YOU SO MUCH for the hint in b4a-chat just before i lost connection to it, @thedesolatesoul !!!!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The server went down i think. But you were at work in the background!
Let me say again a HUGE BIG THANK YOU at this point! The point with the nativelibs did the job! YES!
Thank you for this hint!!!! :) You rule :D

The library now uses the most actual SDK and Datastore can be declared as shareable resp. shared. GREAT! :D
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
First Example Online (See Post #1)

The Maincode is the copying of some data from the sqlite-database to the Datastore.

Here is the code (Full source is included in Example1 in Post #1)

B4X:
Sub MenuCopycustomers_Click
    Log("MenuCopycustomers")
    If ds.IsInitialized = False Then
        Log("Datastore is not Initialized.")
    Else
        Log("Datastore is Initialized. Title: "&ds.Title)
        Dim Row As Int
        Dim cur As Cursor
     
        '
        ' Table Customers
        '
        Dim t As DbxTable = ds.getTable("Customers")
        Dim res As QueryResult = t.query
        Dim l As List = res.GetAll
        Log("SizeOfCustomers="&l.Size)
        datastore.Clear
        For i = 0 To l.Size -1
            'Log(l.Get(i))
            Dim rec As DbxRecord  = l.Get(i)
            rec.deleteRecord         
        Next

        'We read only the ID column and put them in a List
        cur = db.ExecQuery("SELECT * FROM Customers")
        If cur.RowCount > 0 Then                        'check if entries exist
            RowNumber = cur.RowCount                    'set the row count variable
            For Row = 0 To cur.RowCount - 1
                cur.Position = Row                            'set the Cursor to each row
                'Dim rec As DbxRecord = t.getOrInsert(cur.GetString("CustomerID"))
                Dim rec As DbxRecord = t.Insert()
                For i = 0 To cur.ColumnCount-1
                    Log(cur.GetColumnName(i)&"="&cur.GetString(cur.GetColumnName(i)))
                    If cur.GetString(cur.GetColumnName(i)) = Null Then
                        rec.setString(cur.GetColumnName(i),"")
                    Else
                        rec.setString(cur.GetColumnName(i),cur.GetString(cur.GetColumnName(i)))
                    End If
                Next
                Log(rec.asMap)
                'rec.setString("str","Teststring")
                'rec.setString("str2","Teststring2")
                'rec.setString("str3","Teststring3")
                'rec.setDate("datum",DateTime.Now)
                'rec.setLong("long",123456)
                'rec.setBoolean("boolean",False)
                'rec.setDouble("double",3.14)
                         
                Log(cur.GetString("CustomerID")&":"&cur.GetString("CompanyName"))
            Next
            ds.Sync
            CurrentIndex = 0                                            'set the current index to 0
        End If
        cur.Close                                                        'close the cursor, we don't need it anymore

        '
        ' Table Categories
        '
        Dim t As DbxTable = ds.getTable("Categories")
        Dim res As QueryResult = t.query
        Dim l As List = res.GetAll
        Log("SizeOfCategories="&l.Size)
        datastore.Clear
        For i = 0 To l.Size -1
            'Log(l.Get(i))
            Dim rec As DbxRecord  = l.Get(i)
            rec.deleteRecord         
        Next
        cur.Close                                                        'close the cursor, we don't need it anymore

        'We read only the ID column and put them in a List
        cur = db.ExecQuery("SELECT * FROM Categories")
        If cur.RowCount > 0 Then                        'check if entries exist
            RowNumber = cur.RowCount                    'set the row count variable
            For Row = 0 To cur.RowCount - 1
                cur.Position = Row                            'set the Cursor to each row
                'Dim rec As DbxRecord = t.getOrInsert(cur.GetString("CustomerID"))
                Dim rec As DbxRecord = t.Insert()
                Dim BlobBuffer() As Byte
                BlobBuffer = cur.GetBlob("Picture")

                rec.setString("CategoryID",CheckNull(cur.GetString("CategoryID")))
                rec.setString("CategoryName",CheckNull(cur.GetString("CategoryName")))
                rec.setString("Description",CheckNull(cur.GetString("Description")))
                rec.setByte("Picture",BlobBuffer)
                Log(rec.asMap)
                'rec.setString("str","Teststring")
                'rec.setString("str2","Teststring2")
                'rec.setString("str3","Teststring3")
                'rec.setDate("datum",DateTime.Now)
                'rec.setLong("long",123456)
                'rec.setBoolean("boolean",False)
                'rec.setDouble("double",3.14)
                         
                Log(cur.GetString("CategoryID")&":"&cur.GetString("CategoryName")&":"&cur.GetString("Description"))
            Next
            ds.Sync
            CurrentIndex = 0                                            'set the current index to 0
        End If
        cur.Close                                                        'close the cursor, we don't need it anymore

        '
        ' Table Employees
        '
        Dim t As DbxTable = ds.getTable("Employees")
        Dim res As QueryResult = t.query
        Dim l As List = res.GetAll
        Log("SizeOfCategories="&l.Size)
        datastore.Clear
        For i = 0 To l.Size -1
            'Log(l.Get(i))
            Dim rec As DbxRecord  = l.Get(i)
            rec.deleteRecord         
        Next
        cur.Close                                                        'close the cursor, we don't need it anymore

        'We read only the ID column and put them in a List
        cur = db.ExecQuery("SELECT * FROM Employees")
        If cur.RowCount > 0 Then                        'check if entries exist
            RowNumber = cur.RowCount                    'set the row count variable
            For Row = 0 To cur.RowCount - 1
                cur.Position = Row                            'set the Cursor to each row
                'Dim rec As DbxRecord = t.getOrInsert(cur.GetString("CustomerID"))
                Dim rec As DbxRecord = t.Insert()
                Dim BlobBuffer() As Byte
                'cur.GetBlob("Photo")

                rec.setLong("EmployeeID",cur.GetString("EmployeeID"))
                rec.setString("LastName",CheckNull(cur.GetString("LastName")))
                rec.setString("FirstName",CheckNull(cur.GetString("FirstName")))
                rec.setString("Title",CheckNull(cur.GetString("Title")))
                rec.setString("TitleOfCourtesy",CheckNull(cur.GetString("TitleOfCourtesy")))
                rec.setString("Address",CheckNull(cur.GetString("Address")))
                rec.setString("City",CheckNull(cur.GetString("City")))
                rec.setString("Region",CheckNull(cur.GetString("Region")))
                rec.setString("PostalCode",CheckNull(cur.GetString("PostalCode")))
                rec.setString("Country",CheckNull(cur.GetString("Country")))
                rec.setString("HomePhone",CheckNull(cur.GetString("HomePhone")))
                rec.setString("Extension",CheckNull(cur.GetString("Extension")))
                rec.setString("Notes",CheckNull(cur.GetString("Notes")))
                rec.setString("PhotoPath",CheckNull(cur.GetString("PhotoPath")))
                Dim BlobBuffer() As Byte
                BlobBuffer = cur.GetBlob("Photo")
                rec.setByte("Photo",BlobBuffer)
                rec.setString("BirthDate",cur.GetLong("BirthDate"))
                rec.setString("HireDate",cur.GetLong("HireDate"))

                Log(rec.asMap)
                'rec.setString("str","Teststring")
                'rec.setString("str2","Teststring2")
                'rec.setString("str3","Teststring3")
                'rec.setDate("datum",DateTime.Now)
                'rec.setLong("long",123456)
                'rec.setBoolean("boolean",False)
                'rec.setDouble("double",3.14)
                         
                Log(cur.GetString("EmployeeID")&":"&cur.GetString("LastName")&", "&cur.GetString("FirstName"))
            Next
            ds.Sync
            CurrentIndex = 0                                            'set the current index to 0
        End If
        cur.Close                                                        'close the cursor, we don't need it anymore

    End If
End Sub



and the maincode fillling the ListView is

B4X:
Sub lv_ItemClick (Position As Int, Value As Object)
    Log("lv_ItemClick("&Position&", "&Value&")")
    Dim t As DbxTable = ds.getTable(Value)
    Dim res As QueryResult = t.query
    Dim l As List = res.GetAll
    Log("SizeOf("&Value&")="&l.Size)
    datastore.Clear
    For i = 0 To l.Size -1
        'Log(l.Get(i))
        Dim rec As DbxRecord  = l.Get(i)
        'Log(rec.fieldNames)
        'Select Value
        'Case "Categories"
        If Value = "Categories" Then
            Dim bmp As Bitmap
            Dim In1 As InputStream
          Dim buffer() As Byte           
            buffer = rec.getBytes("Picture")
            In1.InitializeFromBytesArray(buffer,0,buffer.Length)
            bmp.Initialize2(In1)           
            datastore.AddTwoLinesAndBitmap2(rec.asMap.Get("CategoryName"),rec.asMap.Get("Description"),bmp,rec.asMap)
        Else If Value = "Employees" Then
            Dim bmp As Bitmap
            Dim In1 As InputStream
          Dim buffer() As Byte           
            buffer = rec.getBytes("Photo")
            In1.InitializeFromBytesArray(buffer,0,buffer.Length)
            bmp.Initialize2(In1)           
            datastore.AddTwoLinesAndBitmap2(rec.asMap.Get("LastName")&", "&rec.asMap.Get("FirstName"),rec.asMap.Get("Address"),bmp,rec.asMap)
        Else   
            datastore.AddTwoLines2(rec.asMap.Get("datum"),rec.asMap,rec.asMap)
        End If
        Log("Map="&rec.asMap)
        'rec.
        'Log(rec)
        'Dim rec As DbxRecord = l.Get(i)
        'Log(rec.fieldNames)
    Next

    'Dim retmap As Map = Value   
End Sub

 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I would like to know whether someone has used the example and HE/SHE can use the Datastore with the ID i have included in Example??? This DS should be PUBLIC and EDITABLE by evryone who know the ID....
Feel free to use this ID and put data into this datastore to test this functionality of the library! ;)
 
Upvote 0

LorenzoTRANSFEREX

Member
Licensed User
Longtime User
I would like to know whether someone has used the example and HE/SHE can use the Datastore with the ID i have included in Example??? This DS should be PUBLIC and EDITABLE by evryone who know the ID....
Feel free to use this ID and put data into this datastore to test this functionality of the library! ;)
I don't able to use ds with your id, but I don't know if I am doing something worng because it don't work with my own id...
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi DonManfred
I saw properties "Path" documented but i dont see in the lib

Screenshot 2015-03-27 06.18.10.png



The question is...after loading a file exists the way to get the link, example:

B4X:
manager.UploadFile(File.DirRootExternal,"devil_logoxxx.jpg","/123/","devil_logoxxx.jpg")
Dim return_path as String
return_path = filemanger.path
or another thing.....

and we get this:

B4X:
https://dl.dropboxusercontent.com/s/zrttoa6f74ij3ta/ico_recordocall.png?dl=0

Thank you in advance
Marco
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I saw properties "Path" documented but i dont see in the lib
Path is a property of DbxFileinfo not of the DropboxManager.

The question is...after loading a file exists the way to get the link
Please try the Version here 3.31

With this Version you can get the url after you get a filelist

B4X:
        Dim files As List = manager.ListFiles("/")   
        For i = 0 To files.Size -1
            Dim fi As DbxFileInfo = files.Get(i)
            Dim fs As DbxFileSystem = manager.fileSystem
            log(fs.fetchShareLink(fi.Path,False)) ' Normal link like the one you posted
            log(fs.fetchShareLink(fi.Path,true)) ' A shortenened version of the downloadlink
        Next
 
Upvote 0
Top