|
@@ -195,13 +195,7 @@ class AddEntry < Riddl::Implementation
|
|
|
db.execute("INSERT OR REPLACE INTO Entries (alldata, cpeeInstance) VALUES (?,?)",JSON.dump(newEntry["alldata"]), "Direkt")
|
|
|
hash = {__orderID__: db.execute("select last_insert_rowid()")[0], alldata: JSON.dump(newEntry["alldata"]), cpeeInstance: "Direkt"};
|
|
|
end
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
@a[0].send("reset")
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
nil
|
|
|
|
|
|
end
|
|
@@ -526,6 +520,77 @@ class SearchPK < Riddl::Implementation
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+def sqlite_json_path(*segments)
|
|
|
+ raise ArgumentError, "at least one segment required" if segments.empty?
|
|
|
+
|
|
|
+ segments.map! { |s| s.to_s }
|
|
|
+ # Escape " and \ inside a quoted segment
|
|
|
+ esc = ->(s) { s.gsub(/["\\]/) { |c| "\\#{c}" } }
|
|
|
+
|
|
|
+ out = "$"
|
|
|
+ segments.each do |seg|
|
|
|
+ if seg =~ /\A\d+\z/
|
|
|
+ # pure array index
|
|
|
+ out << "[#{seg}]"
|
|
|
+ elsif seg =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/
|
|
|
+ # simple identifier -> dot notation
|
|
|
+ out << ".#{seg}"
|
|
|
+ else
|
|
|
+ # needs quoting -> bracket notation
|
|
|
+ out << %Q{["#{esc.call(seg)}"]}
|
|
|
+ end
|
|
|
+ end
|
|
|
+ out
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+class SearchField < Riddl::Implementation
|
|
|
+ def response
|
|
|
+
|
|
|
+ fname = File.join('data',@r[-2],'data.db')
|
|
|
+ db = SQLite3::Database.open fname
|
|
|
+
|
|
|
+
|
|
|
+ colname = @p[0].value
|
|
|
+ colvalue = @p[1].value
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if !db.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='Entries';").empty?
|
|
|
+ db.results_as_hash = true
|
|
|
+ alldata = {};
|
|
|
+
|
|
|
+ sql_case_b = <<~SQL
|
|
|
+ SELECT e.*
|
|
|
+ FROM Entries AS e
|
|
|
+ JOIN json_each(json_extract(e.alldata, '$')) AS j
|
|
|
+ ON j.key = ?
|
|
|
+ WHERE j.value = ?
|
|
|
+ SQL
|
|
|
+
|
|
|
+ rows = db.execute(sql_case_b, [colname, colvalue])
|
|
|
+
|
|
|
+
|
|
|
+ #rows.each do |row|
|
|
|
+ # puts "#{row['alldata']}"
|
|
|
+ #end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #alldata["data"] = (db.execute "Select * from Entries WHERE " + colname + " = '" + colvalue + "'")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Riddl::Parameter::Complex.new('value','application/json',JSON.dump(rows))
|
|
|
+ else
|
|
|
+ Riddl::Parameter::Complex.new('value','application/json',JSON.dump({}))
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
|
|
|
class GetNext < Riddl::Implementation
|
|
|
def response
|
|
@@ -676,6 +741,7 @@ server = Riddl::Server.new(File.join(__dir__,'/dashboard.xml'), :host => 'localh
|
|
|
end
|
|
|
|
|
|
on resource 'search' do
|
|
|
+ run SearchField if get 'searchColumn'
|
|
|
on resource 'PK' do
|
|
|
on resource '.*' do
|
|
|
run SearchPK if get
|