Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-09

TJSIDBObjectStore.add() not working with a recordtype variable.....

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pedro Pablo Oviedo Vera

Hello people!,
Im facing this problem:

var
  fTransPeliculas: TJSIDBTransaction;
  fTransAlmacen  : TJSIDBObjectStore;
  fSolicitud     : TJSIDBRequest;
begin
  (......)
  fTransPeliculas   :=  gMyDB.transaction(['peliculas'],'readwrite');
  fTransAlmacen     :=  fTransPeliculas.objectStore('peliculas');
  gInfo.clave       :=  gedtClave.value;
  gInfo.anno        :=  gedtFecha.value;
  gInfo.texto       :=  gedtTexto.value;
  fSolicitud        := fTransAlmacen.add(gInfo,'clave');

but from browser consola I recieve the message:
DataError: Data provided to an operation does not meet requirements.

but when use this alternative....
asm
fSolicitud =
fTransAlmacen.add({id:$mod.gInfo.clave,nombre:$mod.gInfo.texto,fecha:$mod.gInfo.anno});

  end;

everything works!!!!
perhaps fSolicitud := fTransAlmacen.add(gInfo,'clave'); is incorrepts ...then how it will be OK?

Thanks
pp

MSc. Ing. Pedro Pablo Oviedo Vera Dirección Técnica y Desarrollo Empresa de Proyectos e Ingeniería del Ministerio de la Agricultura.ENPA. Boyeros y Conill, Piso 10 Edif MINAG Telef. 884 7197 SIP:23000116 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20190920/235204e2/attachment.html>
Michael Van Canneyt
to Pedro Pablo Oviedo Vera
Pedro Pablo Oviedo Vera wrote 32 lines
Hello people!, Im facing this problem: var fTransPeliculas: TJSIDBTransaction; fTransAlmacen : TJSIDBObjectStore; fSolicitud : TJSIDBRequest; begin (......) fTransPeliculas := gMyDB.transaction(['peliculas'],'readwrite'); fTransAlmacen := fTransPeliculas.objectStore('peliculas'); gInfo.clave := gedtClave.value; gInfo.anno := gedtFecha.value; gInfo.texto := gedtTexto.value; fSolicitud := fTransAlmacen.add(gInfo,'clave'); but from browser consola I recieve the message: DataError: Data provided to an operation does not meet requirements. but when use this alternative.... asm fSolicitud = fTransAlmacen.add({id:$mod.gInfo.clave,nombre:$mod.gInfo.texto,fecha:$mod.gInfo.anno}); end; everything works!!!! perhaps fSolicitud := fTransAlmacen.add(gInfo,'clave'); is incorrepts ...then how it will be OK?

first of all, you are doing things very differently
- your asm code does not provide a key, your pascal code does.
- the structure of the object you are saving is very different.

Secondly, to know why it goes wrong, we need to know what is the definition of the object store.

Maybe this answers your question:
https://stackoverflow.com/questions/36016862/indexeddb-dataerror-data-provided-to-an-operation-does-not-meet-requirements

Michael.

Pedro Pablo Oviedo Vera
to Michael Van Canneyt
Yes, you all right!...I am try it ....my problem :
...for example...I declare >>>>>
type
  gsolicitud    : TJSIDBOpenDBRequest;
   gMyDB       : TIDBDatabase;
function fOpenDB(aEvent: TEventlistenerEvent): Boolean;
begin
(* inside event handler I need get params retorned from request   *)
gMyDB  := aEvent.target; <==== but this does not works for me
gMyDB  := gsolicitud.resultAsDatabase; <==== so I must try this !!! :-( but
it is not correct!
end;
begin
  ......
  gsolicitud  := Window.indexedDB.open(gDBName,4);   <<<< I requesting for
this event
  gsolicitud.onsuccess := @fOpenDB;                            <<< and set
this function to handles this event
  ......
end;

When I go to the event handler function I try get params returned through aEvent.target ( gMyDB := aEvent.target; ) but compiler tells type missmacthed!, then I just try solve it do some thing like this ( gMyDB := gsolicitud.resultAsDatabase; )....it is not just in this case ...it happend to me always that I need recover a param inside of an event handler function...so if some one has an answer about it please illustrate me..THANKS

El sáb., 21 sept. 2019 a las 12:17, Michael Van Canneyt (<

Show quoted text 58 lines
) escribió: On Fri, 20 Sep 2019, Pedro Pablo Oviedo Vera wrote: > Hello people!, > Im facing this problem: > > var > fTransPeliculas: TJSIDBTransaction; > fTransAlmacen : TJSIDBObjectStore; > fSolicitud : TJSIDBRequest; > begin > > (......) > > fTransPeliculas := gMyDB.transaction(['peliculas'],'readwrite'); > fTransAlmacen := fTransPeliculas.objectStore('peliculas'); > > gInfo.clave := gedtClave.value; > gInfo.anno := gedtFecha.value; > gInfo.texto := gedtTexto.value; > > fSolicitud := fTransAlmacen.add(gInfo,'clave'); > > but from browser consola I recieve the message: > DataError: Data provided to an operation does not meet requirements. > > but when use this alternative.... > asm > fSolicitud = > fTransAlmacen.add({id:$mod.gInfo.clave,nombre:$mod.gInfo.texto,fecha:$mod.gInfo.anno}); > end; > > everything works!!!! > perhaps fSolicitud := fTransAlmacen.add(gInfo,'clave'); is > incorrepts ...then how it will be OK? first of all, you are doing things very differently - your asm code does not provide a key, your pascal code does. - the structure of the object you are saving is very different. Secondly, to know why it goes wrong, we need to know what is the definition of the object store. Maybe this answers your question: https://stackoverflow.com/questions/36016862/indexeddb-dataerror-data-provided-to-an-operation-does-not-meet-requirements Michael. _______________________________________________ Pas2js maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
MSc. Ing. Pedro Pablo Oviedo Vera Dirección Técnica y Desarrollo Empresa de Proyectos e Ingeniería del Ministerio de la Agricultura.ENPA. Boyeros y Conill, Piso 10 Edif MINAG Telef. 884 7197 SIP:23000116 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20191002/7d9d9060/attachment.html>
Michael Van Canneyt
to Pedro Pablo Oviedo Vera
Pedro Pablo Oviedo Vera wrote 10 lines
Yes, you all right!...I am try it ....my problem : ...for example...I declare >>>>> type gsolicitud : TJSIDBOpenDBRequest; gMyDB : TIDBDatabase; function fOpenDB(aEvent: TEventlistenerEvent): Boolean; begin (* inside event handler I need get params retorned from request *) gMyDB := aEvent.target; <==== but this does not works for me

You must typecast this, this is always so.

Just like in Delphi/FPC the Sender :TObject is used as a generic sender, event.target is also very generic. So you must always do

gMyDB  := TIDBDatabase(aEvent.target);

That is normal.

Michael.

Pedro Pablo Oviedo Vera
to Michael Van Canneyt

just this??!!!!....ok let's go!!

Thanks a lot!!!!

El mié., 2 oct. 2019 a las 12:46, Michael Van Canneyt (<

Show quoted text 31 lines
) escribió: On Wed, 2 Oct 2019, Pedro Pablo Oviedo Vera wrote: > Yes, you all right!...I am try it ....my problem : > ...for example...I declare >>>>> > type > gsolicitud : TJSIDBOpenDBRequest; > gMyDB : TIDBDatabase; > > function fOpenDB(aEvent: TEventlistenerEvent): Boolean; > begin > (* inside event handler I need get params retorned from request *) > gMyDB := aEvent.target; <==== but this does not works for me You must typecast this, this is always so. Just like in Delphi/FPC the Sender :TObject is used as a generic sender, event.target is also very generic. So you must always do gMyDB := TIDBDatabase(aEvent.target); That is normal. Michael. _______________________________________________ Pas2js maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
MSc. Ing. Pedro Pablo Oviedo Vera Dirección Técnica y Desarrollo Empresa de Proyectos e Ingeniería del Ministerio de la Agricultura.ENPA. Boyeros y Conill, Piso 10 Edif MINAG Telef. 884 7197 SIP:23000116 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20191002/60aca637/attachment.html>