From 498373e44fa6e21726b24585649efad2b599eee8 Mon Sep 17 00:00:00 2001 From: Rafael de Figueiredo Alves Date: Sat, 27 May 2023 22:06:44 -0300 Subject: [PATCH] Update May 27, 2023 - Removed asDataSet method (to be implemented in the near future) --- Comandos.txt | 2 + Demos/Simple Demo/UnitMain.pas | 11 +++- Demos/Simple Demo/UnitMain.vlb | 37 +++++++++++ .../eFirebase.Responses.RealTimeDB.pas | 62 ++++++++++++++++--- source/eFirebase.Interfaces.pas | 3 +- source/eFirebase.pas | 2 +- 6 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 Comandos.txt create mode 100644 Demos/Simple Demo/UnitMain.vlb diff --git a/Comandos.txt b/Comandos.txt new file mode 100644 index 0000000..18c640e --- /dev/null +++ b/Comandos.txt @@ -0,0 +1,2 @@ + //auth := TeFirebase.New.Auth('AIzaSyCeUiXhD5rL0QgHoV1C8WkCg17n9n5teew').ChangeProfile('eyJhbGciOiJSUzI1NiIsImtpZCI6ImY4NzZiNzIxNDAwYmZhZmEyOWQ0MTFmZTYwODE2YmRhZWMyM2Iz' + 'ODIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZXRhc2' + 'tzLWQ2OTg4IiwiYXVkIjoiZXRhc2tzLWQ2OTg4IiwiYXV0aF90aW1lIjoxNjc3NDU1NTEzLCJ1c2VyX2lkIjoiWDZ4bDJ' + 'iYzUwclRCVGpFZXZ4eVNoMVNRYU1iMiIsInN1YiI6Ilg2eGwyYmM1MHJUQlRqRWV2eHlTaDFTUWFNYjIiLCJ' + 'pYXQiOjE2Nzc0NTU1MTMsImV4cCI6MTY3NzQ1OTExMywiZW1haWwiOiJmYW1pbGlhLmFsdmVzMjAxM0BvdX' + 'Rsb29rLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJmYW1p' + 'bGlhLmFsd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udGl0aWVzIjp7ImVtYWlsIjpbImZhbWlsaWEuYWx2ZXMyMDEzQG91dGxvb2suY29tIl19LCJzaWduX2luX3Byb' + '3ZpZGVyIjoicGFzc3dvcmQifX0.pZFLjPm6zA7BaUiUVE05ghDNJVaC3WZXlFkrYcEFQAUCr6p18wAaKw8r7_M2XRD-IoYBGNZlPaBj1L8b4eJjTywPHyy6pWkSqvx32t27Qzm4I5AcxczQAmQ' + 'RB3jU_hY8WLPHrhc1svHSx_Hm5difRKEILZlH3cNaoFpfZweC_1V2GCn2g99HbygBWjBSzs4zhby-x5oqYjBkFy9sGusySqX841vt4Y_QDp9r_IDvvgCa77DCHxfo4PEVB_hamDFK-NfiMfQgFE0t3vefZKUHO_Fbk6v1ULjMe6snUwJdiv3XAmCF-8tNkHDPXgEzQ9ACzCvm-lal1VlSr_wjgKul_w'); \ No newline at end of file diff --git a/Demos/Simple Demo/UnitMain.pas b/Demos/Simple Demo/UnitMain.pas index ad453ae..1132202 100644 --- a/Demos/Simple Demo/UnitMain.pas +++ b/Demos/Simple Demo/UnitMain.pas @@ -6,7 +6,12 @@ interface System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit, - FMX.Objects; + FMX.Objects, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, + FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, + System.Rtti, FMX.Grid.Style, Data.Bind.EngExt, Fmx.Bind.DBEngExt, + Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors, + Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope, FMX.Grid, Data.DB, + FireDAC.Comp.DataSet, FireDAC.Comp.Client, Datasnap.DBClient; type TForm2 = class(TForm) @@ -48,8 +53,7 @@ procedure TForm2.Button1Click(Sender: TObject); auth: ieFirebaseResponseAuth; begin auth := TeFirebase.New.Auth('AIzaSyCeUiXhD5rL0QgHoV1C8WkCg17n9n5teew').SignInWithEmailPassword('familia.alves2013@outlook.com', 'Roblox2023'); - //auth := TeFirebase.New.Auth('AIzaSyCeUiXhD5rL0QgHoV1C8WkCg17n9n5teew').ChangeProfile('eyJhbGciOiJSUzI1NiIsImtpZCI6ImY4NzZiNzIxNDAwYmZhZmEyOWQ0MTFmZTYwODE2YmRhZWMyM2Iz' + 'ODIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZXRhc2' + 'tzLWQ2OTg4IiwiYXVkIjoiZXRhc2tzLWQ2OTg4IiwiYXV0aF90aW1lIjoxNjc3NDU1NTEzLCJ1c2VyX2lkIjoiWDZ4bDJ' + 'iYzUwclRCVGpFZXZ4eVNoMVNRYU1iMiIsInN1YiI6Ilg2eGwyYmM1MHJUQlRqRWV2eHlTaDFTUWFNYjIiLCJ' + 'pYXQiOjE2Nzc0NTU1MTMsImV4cCI6MTY3NzQ1OTExMywiZW1haWwiOiJmYW1pbGlhLmFsdmVzMjAxM0BvdX' + 'Rsb29rLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJmYW1p' + 'bGlhLmFsdmVzMjAxM0BvdXRsb29rLmNvbSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.V-ERTuN' + 'WPquSwO-LqRSeF_sUsboLOaKdFm7esq1A_8eSmXHBZIp1YlDWHJuxcylcbgSwn2vrQP5xJEQ_AqPIZ' + 'ZGLOLU0khIoW2VM90VZRdYWNbpbnaTr2Du3RswyvXFpOhguEsgehD45Q0NEmwvSauo0YKZgbr-RGdYiF1TeGrAczAQwAXrdG' + 'ga-RCYjTCbW9uJMIKPOU5rhtkrghnhIIKGh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BWjBSzs4zhby-x5oqYjBkFy9sGusySqX841vt4Y_QDp9r_IDvvgCa77DCHxfo4PEVB_hamDFK-NfiMfQgFE0t3vefZKUHO_Fbk6v1ULjMe6snUwJdiv3XAmCF-8tNkHDPXgEzQ9ACzCvm-lal1VlSr_wjgKul_w'); + if auth.StatusCode = 200 then ShowMessage('Conta apagada com sucesso!'); @@ -157,6 +161,7 @@ procedure TForm2.Button5Click(Sender: TObject); if arrJSON.Items[0].TryGetValue('categoria', teste) then Memo1.Lines.Add(teste); arrJSON.DisposeOf; + end; procedure TForm2.FormCreate(Sender: TObject); diff --git a/Demos/Simple Demo/UnitMain.vlb b/Demos/Simple Demo/UnitMain.vlb new file mode 100644 index 0000000..e90a738 --- /dev/null +++ b/Demos/Simple Demo/UnitMain.vlb @@ -0,0 +1,37 @@ +[Memo1] +Coordinates=292,10,49,51 + +[Edit1] +Coordinates=129,10,40,51 + +[Button3] +Coordinates=10,146,53,51 + +[Label2] +Coordinates=10,10,46,51 + +[Button5] +Coordinates=148,78,53,51 + +[Image1] +Coordinates=217,78,49,51 + +[Button2] +Coordinates=79,78,53,51 + +[OpenDialog1] +Coordinates=266,155,77,33 + +[Button4] +Coordinates=10,78,53,51 + +[Button1] +Coordinates=284,78,53,51 + +[Label1] +Coordinates=79,146,46,51 + +[] +Coordinates=239,148,82,33 +Visible=True + diff --git a/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas b/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas index 8e0ed8c..67b70c8 100644 --- a/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas +++ b/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas @@ -22,7 +22,8 @@ interface function AsJSONstr: string; function AsJSONObj: tJSONObject; function AsJSONArray: TJSONArray; - function AsDataSet(out DataSet: tDataSet) : integer; + {TODO -oRafael -cImplementar : Implementar esta função no futuro, quando descobrir ponto que está dando Access Violation} + //function AsDataSet(out DataSet: tDataSet) : integer; End; implementation @@ -33,6 +34,13 @@ implementation { TeFirebaseRealtimeResponse } +function RemoveQuotes(const text: string) : string; +begin + Result := text.Replace('"', ''); + Result := Result.TrimLeft; + Result := Result.TrimRight; +end; + constructor TeFirebaseRealtimeResponse.Create(const Response: string; StatusCode: integer; eTag: string); begin fResponse := Response; @@ -78,13 +86,6 @@ function TeFirebaseRealtimeResponse.AsJSONArray: TJSONArray; NewObj : TJSONObject; Par : integer; Valor : TJsonObject; - - function RemoveQuotes(const text: string) : string; - begin - Result := text.Replace('"', ''); - Result := Result.TrimLeft; - Result := Result.TrimRight; - end; begin Obj := Self.AsJSONObj; try @@ -107,9 +108,50 @@ function TeFirebaseRealtimeResponse.AsJSONArray: TJSONArray; end; -function TeFirebaseRealtimeResponse.AsDataSet(out DataSet: tDataSet) : integer; +{function TeFirebaseRealtimeResponse.AsDataSet(out DataSet: tDataSet) : integer; +var + arrJSON : TJSONArray; + Reg : TJSONObject; + I : integer; + Field : TField; + Item : Integer; + Valor : string; + teste : string; + teste1 : Array of TVarRec; begin Result := fStatusCode; -end; + arrJSON := AsJSONArray; + try + if (arrJSON.Count > 0) and Assigned(DataSet) then + begin + Reg := arrJSON.Items[0] as TJSONObject; + + DataSet.Fields.Clear; + + for I := 0 to Reg.Count - 1 do + begin + Field := TStringField.Create(nil); + Field.FieldKind := fkData; + Field.FieldName := RemoveQuotes(Reg.Pairs[i].JsonString.ToString); + DataSet.Fields.Add(Field); + end; + + DataSet.Open; + for Item := 0 to arrJSON.Count - 1 do + begin + SetLength(teste1, Reg.Count); + for I := 0 to Reg.Count - 1 do + begin + Valor := EmptyStr; + arrJSON.Items[Item].TryGetValue(RemoveQuotes(Reg.Pairs[i].JsonString.ToString), Valor); + teste1[i] := TVarRec(Valor); + end; + DataSet.AppendRecord(teste1); + end; + end; + finally + arrJSON.DisposeOf; + end; +end;} end. diff --git a/source/eFirebase.Interfaces.pas b/source/eFirebase.Interfaces.pas index 29c0f55..3e0bcff 100644 --- a/source/eFirebase.Interfaces.pas +++ b/source/eFirebase.Interfaces.pas @@ -41,7 +41,8 @@ interface function AsJSONstr: string; function AsJSONObj: tJSONObject; function AsJSONArray: TJSONArray; - function AsDataSet(out DataSet: tDataSet) : integer; + {TODO -oRafael -cImplementar : Implementar esta função no futuro, quando descobrir ponto que está dando Access Violation} + //function AsDataSet(out DataSet: tDataSet) : integer; end; {$Endregion} diff --git a/source/eFirebase.pas b/source/eFirebase.pas index 8c5e81d..f13bbac 100644 --- a/source/eFirebase.pas +++ b/source/eFirebase.pas @@ -29,7 +29,7 @@ interface End; const - eFirebase_VERSION = '0.0.12-a'; + eFirebase_VERSION = '0.0.13-a'; implementation