I'm using XQuery to go over a bunch of XML files and extract indexed terms and turn them into SQL insert statements. This is very straightforward:
xquery version "3.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
for $index in collection(/db/letters/)//index/text()
return
concat("INSERT INTO `indices` SET index='", $index, "';")
This generates statements like:
INSERT INTO `indices` SET index='foo';
INSERT INTO `indices` SET index='bar';
which is all fine and dandy. But I would like to output some text once before and once after all those statements, namely, first:
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `indices`
-- ----------------------------
DROP TABLE IF EXISTS `indices`;
CREATE TABLE `indices` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`norm` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT;
and, at the end,
SET FOREIGN_KEY_CHECKS = 1;"
In PHP this would be a non-brainer, but in XQuery it's much more difficult, especially for non-advanced users like myself.
The FLOWR expressions seem very easy and logical when outputting XML, but I can't figure out how to concat the cumulative return with two other strings.
Any pointers will be warmly appreciated.