Custom type is not a map

CharlesIPTI

Active Member
Licensed User
Longtime User
This is from teh DBUtils Sample project
FillGradesTable

Its using map M and a list thereOf

I instead have a custom type CLocation and a list of these types.
B4X:
Type CLocation(dbId As Int, locNm As String, sku As String, _
shlf As Int,ori As Int,sho As Boolean, ot As Boolean, wlkSeq As Int)
I'm going to have to do this manually aren't I ???!?!


B4X:
   For test = 1 To 20
      For student = 0 To Table.Size - 1
         Dim m As Map
         m.Initialize
         Cols = Table.Get(student)
         m.Put("Id", Cols(0))
         m.Put("Test", "Test #" & test)
         m.Put("Grade", Rnd(0, 101)) 'The upper value is exclusive
         ListOfMaps.Add(m)
      Next
   Next
   DBUtils.InsertMaps(SQL, "Grades", ListOfMaps)
 

CharlesIPTI

Active Member
Licensed User
Longtime User
Nope

Map entries will duplicate
and thats not allowed...

Object CLocation
properties

m.Initialize
m.Put("DBID", DBUtils.DB_TEXT)
m.Put("LocationName", DBUtils.DB_TEXT)
m.Put("SKU", DBUtils.DB_TEXT)
m.Put("Shelf", DBUtils.DB_INTEGER)
m.Put("Orientation", DBUtils.DB_INTEGER)
m.Put("Short", DBUtils.DB_INTEGER)
m.Put("Out", DBUtils.DB_INTEGER)
m.Put("WalkSequence", DBUtils.DB_INTEGER)

Your sure to get the same Shelf number or short or out or Orientation values
between at least a few instances of the object (whoops I mean type) so that would mess up the map concept not allowing you to have a list of map objects to feed to the method SQL.InsertMap....


Presently I'm just populating a single instance of the type AKA its properties into a set of map instances
and then push that into SQL.Insert Map.. One at a time

So I'm inserting one type instance at a Time avoiding duplications in the instance of map's key value pairs that I would run into if I attempt to "put in" several instances of the type.

It may be fast enough (a thousand or so individual SQL pushes) rather than than trying to parametrize out an insert statement and build up a string builder.. ??
I don't know for sure...

Pseudo Code manual Build up of Insert statement :

append to insert stringBuilder,
Dim sb as StringBuilder

sb .Append( blah blah ----

insert
ColNm1 ColNm2, ColNm3
Values

' LOOP through Each CLocation Object to provide values for insert statement



For I =1 To ListofClocationObjects.Size ' check for zero based Kraziness
Dim objSpecificInstance as CLocation
objSpecificInstance = ListofClocationObjects(I)

sb .Append(

objSpecificInstance .DBID, objSpecificInstance .SKU, objSpecificInstance .Shelf )

and so on... I may get around to trying something ugly like this today too .


Sorry as appropriate No offense intended &
Again I TRULY
APPRECIATE ALL replies...


I'm just not looking forward to this kind of tedium today..

please forgive my ranting thanks :eek: :sign0089:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your sure to get the same Shelf number or short or out or Orientation values
between at least a few instances of the object (whoops I mean type) so that would mess up the map concept not allowing you to have a list of map objects to feed to the method SQL.InsertMap....

I think that there is some confusion about the usage of maps here.

The only limitation of maps is that the keys in the same map must be unique.
In your case there is no problem as you have a list made of maps. It doesn't matter if one map has the same keys as a different map.

My solution will work perfectly, and is also quite simple.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
yes Agreed

My retests confirmed the map model and the requirement for just the unique ID

Thanks for the follow up,

I successfully persisted the list of maps

Issue Closed:
 
Upvote 0

macnlkc

Member
Licensed User
Longtime User
Charles, can you post an example of how you accomplished this? This is very similar to what I am trying to do in one of my projects and I could use the help. Thanks!
 
Upvote 0
Top