validate XML with RelaxNG in BaseX DB - basex

I want to validate XMLs against RelaxNG schema which is stored in BaseX DB.
I have also stored RelaxNG schema in DB but when I am validating it is throwing the error below.
Code for validation:
let $binary := db:retrieve('onix','/relaxng/publishers-51cr.rnc')
let $schema := bin:decode-string($binary)
return
let $input := db:open('onix')
return validate:rng($input, $schema)
When I run the query, it throws the error:
Invalid XML character(20)
So it is giving the error while decoding binary.

If the RelaxNG schema is a compact one, the third argument must be true().

Related

Storing Files in SQL Server Table (varbinary(max) column) using ADOQuery Component

I'm using SQL Server 2019 and Delphi 10.3.
I need to store any kind of files ( like pdf, txt, docx, etc) in a 'Personal_Files' table.
This table is composed by a column with the file extension ( as varchar) and a varbinary(max) column to store the file itself.
I did some research on how to store these files on a table, but without success. Below some example:
var
Input,Output: TStream;
FName: TFileName;
begin
...
//Create Streams and encode Base64:
Input := TFileStream.Create(FName,fmOpenRead);
Output := TFileStream.Create(FName+'Temp',fmCreate);
TNetEncoding.Base64.Encode(Input,Output);
... // Some validations
// In the ADOQuery component, I did this:
with ADOQuery, sql do
begin
close;
clear;
add('INSERT INTO MyDatabase.dbo.MyFilesTable (EXTENSION,FILEBIN)');
add('VALUES (:wextension, :wfilebin)');
Parameters.ParamByName('wextension').Value := TPath.GetExtension(FName);
Parameters.ParamByName('wfilebin').Value := Output.toString;
ExecSQL;
end;
In this example, I tried to parse the stream as String, after the encode, but when I look in the SQL Table, it's the same stream for all the archives I tried. The parameter doesn't accept TStream type. Thank you in advance.
After some research, and some advices, I found a way to send the file to my SQL Server table with ADOQuery. Altough, I learned that this isn't recommended, so it's just to answer my question directly:
Just a change on the final part of the code answers my question ( but again, it's not the recommended way to store files, as commented on the question.):
with ADOQuery, sql do
begin
close;
clear;
add('INSERT INTO MyDatabase.dbo.MyFilesTable (EXTENSION,FILEBIN)');
add('VALUES (:wextension, :wfilebin)');
Parameters.ParamByName('wextension').Value := TPath.GetExtension(FName);
Parameters.Items[1].LoadFromStream(Output,ftVarBytes);
ExecSQL;
end;
Just changing the way I was setting the parameter solved the problem. In this example, using the 'LoadFromStream' on the Paremeters.Items[n], where n is the parameter index, it worked very well. The ftVarBytes is the field type parameter.

DolphinDB error: SegmentedTable does not support direct access. Please use sql query to retrieve data

dbDir = '/tests/dolphindb/valueDB'
devDir = '/tests/dolphindb/dev.csv'
db = database(dbDir)
dev = db.loadTable(`dev)
saveText(dev, devDir)
I want to export table "dev" as 'csv' file but I encountered this error message:
Execution was completed with exception
SegmentedTable does not support direct access. Please use sql query to retrieve data
I wonder if I have to load all data into memory to export it as 'csv' file.
Yes, the input table for saveText must be a non-partitioned table.

C# Inconsistent work with access databases (OleDb) [duplicate]

I would like to use an Insert Into query in Delphi XE2 to insert a user's information into a MS Access Database. The problem is I keep getting the same error:
Syntax error in INSERT INTO statement
I have done some research but there is no definitive answer. my source code is:
opendb('QuizDB.mdb');
DB.Close;
DB.SQL.Add('INSERT INTO tblUsers');
DB.SQL.Add('(FirstName,Surname,Username,Password,Grade)');
DB.SQL.Add('Values (:Firstname, :Surname, :Username, :Password, :Grade)');
Db.Parameters.ParamByName('Firstname').Value := pFirstname;
Db.Parameters.ParamByName('Surname').Value := pSurname;
Db.Parameters.ParamByName('Username').Value := pUsername;
Db.Parameters.ParamByName('Password').Value := pPassword;
Db.Parameters.ParamByName('Grade').Value := pGrade;
DB.ExecSQL;
QuizDB being the database name, DB being a ADOQuery component and then p(var) being variables received as parameters.
How do I make it work?
PASSWORD is a reserved word in Access so if you use it as a column name you must enclose it in square brackets.
Try this instead:
DB.SQL.Add('INSERT INTO tblUsers ');
DB.SQL.Add('(FirstName,Surname,Username,[Password],Grade) ');

Groovy - Stored procedures that returns an OracleTypes.ARRAY

I have an issue with Groovy SQL while calling a Stored procedure which returns OracleTypes.ARRAY as output parameter.
Java Code (Working fine):
callableStatement.registerOutParameter(37, OracleTypes.ARRAY, DEVICE_RAW_DATA_ARRAY);
OracleTypes.ARRAY registerOutParameter was configured in JDBC(callableStatement), it was working fine.
where as calling the same Stored procedure from Groovy SQL i am getting the following exception "java.sql.SQLException: ORA-03115: unsupported network datatype or representation"
Groovy Code:
import groovy.sql.Sql
def sqlStr = "{call prometheus.PKG_Device_FP_TLDID.SP_Save_Device_FP_Get_TLDID(?,?,?,?,?,?)}"
def params = [ ID_IN,
Request_ID_IN,
Session_ID_IN,
Sql.NUMERIC,
Sql.VARCHAR,
Sql.ARRAY // ARRAY Type output parameter -- Here I am getting Exception "java.sql.SQLException: ORA-03115: unsupported network datatype or representation" //
]
I tried with different DATA TYPES LIKE Sql.ARRAY // OracleTypes.ARRAY // Sql.OracleTypes.ARRAY and other types.
Could you please suggest me the equivalent DATA TYPE for the OracleTypes.ARRAY in Groovy SQL.
Thank you !!

Sql Server: getting the names of the objects involved in errors [duplicate]

How do I correctly extract specific info from an sql error message number 547?
Info Required:
Table Name
Constraint Name
Column Name
Code:
Try
....
Catch ex As System.Data.SqlClient.SqlException
If ex.Number = 547 Then
End If
End Try
Sample message:
UPDATE statement conflicted with COLUMN CHECK constraint
'CK_Birthdate'. The conflict occurred in database 'Northwind', table
'Employees', column 'BirthDate'.
There is no straight forward way of getting these pieces of information separately.
It all gets concatenated into the error message.
You can use select * from sys.messages where message_id=547 to see the various different language formats of the message that you would need to deal with in order to extract the constituent parts then perhaps use regular expressions with capturing groups based around this information.
In addition to queries, here's a powershell script which wraps the sys.messages queries.
http://blogs.msdn.com/b/buckwoody/archive/2009/04/30/and-the-winner-is-get-sql-server-error-messages-from-powershell.aspx
its true there is no straight way to fix this but I did this insted
var str = sqlException.Message.ToString();
var strlist = str.Split(',', StringSplitOptions.RemoveEmptyEntries);
var streplace = strlist[1];
streplace = streplace.Replace("table \"dbo.", "");
streplace = streplace.Replace("\"", ""); //this will get the data table name
streplace = string.Concat(streplace.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');

Resources