Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » [FEATURE REQUEST] Add Jsonize() to S_ structs
[FEATURE REQUEST] Add Jsonize() to S_ structs [message #60060] Wed, 26 July 2023 19:11 Go to next message
omari is currently offline  omari
Messages: 266
Registered: March 2010
Experienced Member
Hi,
I need to serialize a recordset using json, i use this code:
	Array<S_USER> a;
	Sql sql;
	//...
	String js = StoreAsJson(a);



in order to let this work, S_USER (generated from sch file) need to have Jsonize().

this patch add Jsonize to generated S_TABLE structs.
diff --git a/uppsrc/Sql/S_info.cpp b/uppsrc/Sql/S_info.cpp
index 0b89e8236..b47c99e27 100644
--- a/uppsrc/Sql/S_info.cpp
+++ b/uppsrc/Sql/S_info.cpp
@@ -78,6 +78,23 @@ void S_info::Set(const void *s, const ValueMap& m) const
        }
 }

+void S_info::Jsonize(const void *s, JsonIO& json) const
+{
+       if(json.IsStoring()) {
+               for(int i = 0; i < column.GetCount(); i++) {
+                       Value v = Get(s, i);
+                       json(column.GetKey(i), v);
+               }
+       }
+       else {
+               for(int i = 0; i < column.GetCount(); i++) {
+                       Value v;
+                       json(column.GetKey(i), v);
+                       Set(s, i, v);
+               }
+       }
+}
+
 SqlSet S_info::GetSet(const String& prefix) const
 {
        SqlSet set;
diff --git a/uppsrc/Sql/SqlSchema.h b/uppsrc/Sql/SqlSchema.h
index d4a9f797b..4d222c5d5 100644
--- a/uppsrc/Sql/SqlSchema.h
+++ b/uppsrc/Sql/SqlSchema.h
@@ -171,6 +171,8 @@ struct S_info {
        void     Set(const void *s, const SqlId& id, const Value& v) const;
        void     Set(const void *s, const ValueMap& m) const;

+       void     Jsonize(const void *s, JsonIO& json) const;
+
        SqlSet   GetSet(const String& prefix) const;
        SqlSet   GetOf(const SqlId& table) const;

diff --git a/uppsrc/Sql/sch_header.h b/uppsrc/Sql/sch_header.h
index 3ae50ccfc..a15c4a241 100644
--- a/uppsrc/Sql/sch_header.h
+++ b/uppsrc/Sql/sch_header.h
@@ -37,6 +37,7 @@ public: \
        void                        Set(int i, const Upp::Value& v)       { return info->Set(this, i, v); } \
        void                        Set(const Upp::SqlId& id, const Upp::Value& v)  { return info->Set(this, id, v); } \
        void                        Set(const Upp::ValueMap& m)                     { return info->Set(this, m); } \
+       void                        Jsonize(JsonIO& json)                 { return info->Jsonize(this, json); } \
        \
        operator                    const S_info&() const                 { return *info; } \
        \



regards
omari.
Re: [FEATURE REQUEST] Add Jsonize() to S_ structs [message #60064 is a reply to message #60060] Mon, 31 July 2023 01:25 Go to previous message
zsolt is currently offline  zsolt
Messages: 698
Registered: December 2005
Location: Budapest, Hungary
Contributor
I requested it also:
https:// www.ultimatepp.org/forums/index.php?t=msg&th=11554&s tart=0&
Previous Topic: Sqlite bugfix: sqlite has no "nowait" option in select statements
Next Topic: How to make a copy not crypted of a Sqlite db
Goto Forum:
  


Current Time: Tue May 07 06:15:44 CEST 2024

Total time taken to generate the page: 0.02010 seconds