How to use Xquery without xml-database - xquery

I am experimenting with Xquery and have used sedna and basex as xml-databases.
All the examples I have found on internet depend on a database so all the connections need a username/password. What I need however is to use Xquery in combination with just a XML-file (and no database).
What is the best way to create a connection to a file and execute a query?

BaseX provides various operating modes. It can e.g. be used as command-line tool (see http://docs.basex.org/wiki/Startup_Options)...
basex -i input.xml "/your/query"
..or from within Java (see e.g. https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/query/RunQueries.java).
In all cases, there is no need to explicitly create database instances.

You could also try the XQuery command line tools supplied with XmlPrime or Saxon.

Related

How to debug SQLite queries inside a Qt application?

Qt's QSqlDatabase can use SQLite as its backend. I'm trying to find out how to properly debug and optimize my SQLite queries (esp. their execution time) when they run inside a Qt application. This is esp. relevant when there is a difference between their behaviour in a usual SQLite client (such as the sqlite3 command-line client) and inside a Qt application.
Usual debugging and diagnostic techniques no longer work in this context; for example I can't use the dot commands to get information about indexes, track execution time etc. because these commands are specific to the sqlite3 CLI software.
Here are the techniques I found to be the most useful:
Use the CLI. The most obvious is to connect with the sqlite3 command-line client to the same database you are using from your application, and to look up information about indexes etc. there. It also helps to paste a query there that did not work when executed via Qt in order to get more detailed error messages. Obviously this technique won't work when the error is due to a difference of the SQLite3 library used inside Qt vs. the system's library.
Use DB Browser for SQLite. The open source DB Browser for SQLite (sqlitebrowser) is great for debugging issues with SQLite queries that happen in a Qt desktop application but not in the sqlite3 CLI tool. Because this tool is made with Qt itself and can be installed from the Ubuntu repos (sudo apt install sqlitebrowser), so it uses the same Qt as you would use when developing a Qt application for desktop use on that system. That way, it also uses the ame SQLite library that Qt itself uses, whether that is the system's SQLite library or Qt's bundled SQLite library (which depends on how Qt was compiled).
Note that with the default settings queries will take ~4 times longer to execute in sqlitebrowser than in the sqlite3 CLI or in your Qt application. This is approximately proportional for all queries, so it can still be used to improve query efficiency. It can probably be changed on the "PRAGMA" settings page of the software.
Use pragma functions. A difficulty when running diagnostic SQLite queries inside your Qt application is how to obtain their output. There will be no debug messages on the console from the SQLite library. But fortunately most PRAGMA queries that produce output (i.e. diagnostic ones) are also available as PRAGMA functions for use inside SELECT queries. This way, you can return information about indexes etc. inside the tabled results of your SELECT queries.
Use EXPLAIN queries. The SQLite EXPLAIN QUERY PLAN query (and to a lesser degree also the EXPLAIN query) are very useful to analyze why a query is slow. When run inside the sqlite3 CLI software, a EXPLAIN QUERY PLAN query produces a tree-like diagram drawn to the screen. So it does not seem to be a query one could use from inside Qt's SQL implementation, but that actually works. Because this represents actual tabular data, as can be seen from running such a query in any SQLite client that is not the sqlite3 CLI. Example output:
EXPLAIN QUERY PLAN SELECT [...];
id parent notused detail
6 0 0 SEARCH TABLE products USING COVERING INDEX idx_code (code=?)
10 0 0 SEARCH TABLE product_categories USING PRIMARY KEY (product_id=?)
20 0 0 SEARCH TABLE categories USING INTEGER PRIMARY KEY (rowid=?)
Recompile SQLite for debugging. The most extreme measure is to recompile Qt's SQLite3 library with debugging enabled and then to switch on debugging output with PRAGMA vdbe_debug=1;. This should print debug output to stdout while queries run. (I did not test this and it may still be that Qt intercepts this output. But probably not.)

Unable to create query COPY PostgreSQL PQSQL driver

Well the thing is that when the program execute the query to copy a table to a file .CSV. Qt show me the next error.
"ERROR: syntax error at end of input
LINE 1: EXECUTE
Here are the code of the export action:
QSqlQuery qry;
qry.prepare("copy inventory to './inventory.csv'");
if(qry.exec()){
qDebug()<<"Succes";
}else{
qDebug()<<qry.lastError().text();
}
The version of qt is 5.4, used postgresql 9.3 and driver PQSQL working fine just can execute another's query very well like select.
Thanks.
You mentioned that you're using Qt's SQL interface and its PostgreSQL driver.
While Qt's PostgreSQL driver is built on top of PostgreSQL's standard client library libpq, as far as I can tell it does not offer support for lots of the functionality of libpq. In particular, there appears to be no way to access support for the COPY protocol, nor for LISTENing for asynchronous notifications.
You will have to:
libpq directly to COPY ... FROM STDIN
or use regular INSERT statements via Qt; or
Transfer the CSV input to the server, then use COPY ... FROM '/path/on/server' to read the input from a file on the server that the PostgreSQL database is running on, readable by the user the PostgreSQL database runs as.
(You could also submit a patch to Qt to add support for the COPY protocol, which shouldn't be too hard to implement, but is perhaps not the best choice if you're asking this.)
Using COPY needs superuser rights . Do not confuse with \COPY of
PostgreSQL
COPY TO requires absolute path to the output file. If 1st point is
considered, try removing the ./ in your output file name
You can refer to related posts:
post1
and
post2

Create Processing Instruction in BizTalk Map

I know that in BizTalk maps, you can perserve processing instructions. However, the source XML that I will have will not have any processing instructions. However, I will need to create a processing instruction for the Target XML. I know I can write a custom XSLT to do this, however I would like to avoid that as I have the BizTalk map complete except for this.
Can I create processing instructions on the Target XML using only the available functoids in the BizTalk mapper?
Other than using XSLT as you've mentioned, there is also an option to do this on the send port:
Select the native XmlTransmit send pipeline
Add your processing instructions to the
XmlAsmProcessingInstructions property as per this
example

Best way to handle and deploy XQuery stored procedures?

Is there a tool for deploying things into exist? if I've got a bundle of, say, schemas and XQuery stored procedures? Is there a way of, say, bundling those into a zip or tar file and uploading them or deploying them into eXist?
Alternatively what is the best way of storing these things in a version controlled way (in a git repo, say) and deploying them to the eXist server? Ideally, it'd be nice to be able to have a simple script in a scripting language so you can simply call "deploy.py" or whatever and it'd take everything from the repository and load it into the XML database.
The EXpath packaging system specifies a format for generating a ZIP file with XQuery procedures (and other content) and deploying it into multiple XQuery databases.
See the specification. You should be able to use the Python zipfile module to generate these if you're inclined to use Python (though personally, I do so from a makefile).
Unfortunately, the process for checking currently installed package versions to upgrade if necessary is not standardized; I have a solution for BaseX, but nothing for eXist immediately at hand. However, eXist's implementation is well-documented, and you should have little trouble working with it.

do I need to learn sqldeveloper-specific commands for PL/SQL queries?

There are statements like
SET server output ON
PRINT var_name
DEFINE var_name
VARIABLE var_name
etc. which are typed outside the PL/SQL block. These are SQL+ commands which also seem to work on SQlDeveloper, both of which are tools to execute PL/SQL scripts in. Is there any standard that these non-PL/SQL commands follow, i.e. since they are tool-specific, they can differ, say in, SqlDeveloper and SqlPlus. Whose statements should I learn ?
You should learn the commands supported by the tool you are using - SQL Plus commands for SQL Plus, etc. There is overlap between SQL Plus and SQL Developer because SQL Developer has been designed to be easy to use by people who have previously used SQL Plus. To see which SQL Plus commands SQL Developer supports, open its online help and navigate to:
SQL Developer Concepts and Usage
Using the SQL Worksheet
SQL*Plus Statements Supported and Not Supported in SQL Worksheet

Resources