summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-11-03 15:25:04 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2021-11-03 15:25:04 +1300
commit3746ce4682daf46a6c6a0aa25fdbe189d261d5b7 (patch)
treea9d9a1c7b3db26068c236ee6c773f9d40adc850b
parent109379f51430ea057d810791b43ba02c22a30e46 (diff)
Notes are queried
-rw-r--r--src/deck_io.adb39
-rw-r--r--src/deck_io.ads2
2 files changed, 39 insertions, 2 deletions
diff --git a/src/deck_io.adb b/src/deck_io.adb
index 8830df0..c0dd38c 100644
--- a/src/deck_io.adb
+++ b/src/deck_io.adb
@@ -4,6 +4,7 @@ with
Ada.Characters.Latin_1,
Ada.Directories,
+ Ada.Strings.Maps,
Ada.Text_IO,
GNAT.Regpat,
GNATCOLL.JSON,
@@ -19,6 +20,7 @@ package body Deck_IO is
package Latin renames Ada.Characters.Latin_1;
package FD renames Ada.Directories;
+ package Strmap renames Ada.Strings.Maps;
package Pat renames GNAT.Regpat;
package JS renames GNATCOLL.JSON;
@@ -257,12 +259,47 @@ package body Deck_IO is
end Query_Models;
+
+
+ procedure Tokenize_Fields
+ (Raw_Data : in SU.Unbounded_String;
+ Fields : out Field_Vectors.Vector)
+ is
+ Charset : Strmap.Character_Set := Strmap.To_Set (Latin.US);
+ Position : Positive := 1;
+ Next : Natural := 1;
+ begin
+ while Next /= 0 and Position <= SU.Length (Raw_Data) loop
+ Next := SU.Index (Raw_Data, Charset, Position);
+ if Position <= Next then
+ Fields.Append (Field (SU.Unbounded_Slice (Raw_Data, Position, Next - 1)));
+ else
+ Fields.Append (Field (SU.Unbounded_Slice
+ (Raw_Data, Position, SU.Length (Raw_Data))));
+ end if;
+ Position := Next + 1;
+ end loop;
+ end Tokenize_Fields;
+
+
procedure Query_Notes
(Deck : in out Deck_Handle;
Notes : out Note_Vectors.Vector)
is
+ use type SQLite3.Status_Code;
+ Statement : SQLite3.SQLite3_Statement;
+ Current_Note : Note;
+ Raw_Model : SU.Unbounded_String;
begin
- null;
+ Deck.SQL_Handle.Prepare ("SELECT mid, flds FROM notes", Statement);
+ loop
+ Statement.Step;
+ exit when Statement.Status /= SQLite3.SQLITE_ROW;
+ Raw_Model := Statement.Column (0);
+ Current_Note.Model := Model_ID (Raw_Model);
+ Tokenize_Fields (Statement.Column (1), Current_Note.Fields);
+ Notes.Append (Current_Note);
+ end loop;
end Query_Notes;
diff --git a/src/deck_io.ads b/src/deck_io.ads
index 5fe9880..e7723a3 100644
--- a/src/deck_io.ads
+++ b/src/deck_io.ads
@@ -55,7 +55,7 @@ package Deck_IO is
type Field is new SU.Unbounded_String;
package Field_Vectors is new Ada.Containers.Vectors
- (Index_Type => Positive,
+ (Index_Type => Field_Ordinal,
Element_Type => Field);