|
@@ -257,17 +257,19 @@ class SaveReplacement < Riddl::Implementation
|
|
|
#Delete all, afterwards insert
|
|
|
$db.execute("DELETE FROM replacements WHERE station = ? AND patternID = ?", [@r[0], @r[1]])
|
|
|
|
|
|
+ order = 0;
|
|
|
+
|
|
|
doc = Nokogiri::XML(@p[0].value)
|
|
|
doc.xpath(".//item").each do |node|
|
|
|
-
|
|
|
- $db.execute("INSERT INTO replacements (station, patternID, abbreviation, url) VALUES (?,?,?,?)", [@r[0], @r[1], node.xpath(".//abbreviation").text, node.xpath(".//url").text])
|
|
|
+ $db.execute("INSERT INTO replacements (station, patternID, abbreviation, url, ordering) VALUES (?,?,?,?,?)", [@r[0], @r[1], node.xpath(".//abbreviation").text, node.xpath(".//url").text, order])
|
|
|
+ order += 1
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
class GetReplacement < Riddl::Implementation
|
|
|
def response
|
|
|
- result = $db.execute "SELECT * FROM replacements WHERE station = #{@r[0]} and patternID = #{@r[1]}"
|
|
|
+ result = $db.execute "SELECT * FROM replacements WHERE station = #{@r[0]} and patternID = #{@r[1]} ORDER BY ordering ASC"
|
|
|
|
|
|
builder = Nokogiri::XML::Builder.new do |xml|
|
|
|
xml.replacement(){
|
|
@@ -996,7 +998,8 @@ def createDB(opts)
|
|
|
|
|
|
$db.execute "CREATE TABLE IF NOT EXISTS error(station INT, patternID INT, error TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
|
|
|
|
|
|
- $db.execute "CREATE TABLE IF NOT EXISTS replacements(station INT, patternID INT, abbreviation TEXT, url TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
|
|
|
+
|
|
|
+ $db.execute "CREATE TABLE IF NOT EXISTS replacements(station INT, patternID INT, abbreviation TEXT, url TEXT, ordering INT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE)"
|
|
|
|
|
|
$db.execute "CREATE TABLE IF NOT EXISTS image(station INT, patternID INT, imageID INT, language CHARACTER(20), label TEXT, FOREIGN KEY(station, patternID) REFERENCES station(station, patternID) ON DELETE CASCADE,PRIMARY KEY(station,patternID,imageID,language))"
|
|
|
|