Undeclare prefix in XML issue for SQL Server - xml-parsing

I am currently trying to insert an xml node into a table field within SQL server using the below code. I have tried to declare the namespace within the insert but I continue to get undeclared prefix. What am I doing wrong?
Code:
Declare #Term XML = '<wma:Term>My First Term</wma:Term>'
Declare #x XML
Select #x = MetaData from [Products] where Id = 1
Set #x.modify ('declare namespace wma="http://www.google.com/wma"; insert sql:variable("#Term") as last into (/wma:WMA/wma:List)[1]
Expected results:
<wma:WMA xmlns:wma="http://www.google.com/wma">
<wma:List>
<wma:Term>My First Term</wma:Term>
</wma:List>
</wma:WMA>

Related

How to search in SQL with XML data using Entity model?

I have a SQL database where one of the value is a XML string.
Now I'm trying to write a search function to check is it xml string contains a searchstring.
Standard SQL command would be like this:
SELECT
[ID], [DisplayName], [XML_String],
[CreatedTime], [ModifiedTime]
FROM
[Simple_SQL_DB].[dbo].[Simple_Table]
WHERE
CAST(XML_String AS nvarchar(max)) LIKE "%SearchString%"
FROM
Simple_Table
ORDER BY
ModifiedTime DESC)
ORDER BY Displayname
I tried something like this:
private SimpleTableEntities db = new SimpleTableEntities ();
var query = db.Simple_Table
.Where(w => w.XML_String.Cast<string>().Contains("%SearchString%"))
.OrderByDescending(x => x.ModifiedTime);
Unfortunately I get this error:
System.ArgumentException: 'DbExpressionBinding requires an input expression with a collection ResultType.
Can somebody help me to write a correct query?

How to write a SELECT for a field of type "quantity" in SET_GET_ENTITY method?

I want to select a single row with all columns from my table zbookings. zbookings table has a structure based on zbooking data structure - see tables below.
Table ZBOOKINGS:
Structure ZBOOKING:
My BOOKINGSET_GET_ENTITY method:
method BOOKINGSET_GET_ENTITY.
DATA: ls_keytab TYPE LINE OF /IWBEP/T_MGW_NAME_VALUE_PAIR,
i_carrid TYPE string,
i_connid TYPE string,
i_fldate TYPE string,
i_bookid TYPE string.
LOOP AT it_key_tab INTO ls_keytab.
CASE ls_keytab-name.
WHEN 'Carrid'.
i_carrid = ls_keytab-value.
WHEN 'Connid'.
i_connid = ls_keytab-value.
WHEN 'Fldate'.
i_fldate = ls_keytab-value.
WHEN 'Bookid'.
i_bookid = ls_keytab-value.
ENDCASE.
ENDLOOP.
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF er_entity
FROM ybookings AS a
WHERE
a~carrid = i_carrid AND
a~connid = i_connid AND
a~fldate = i_fldate AND
a~bookid = i_bookid.
endmethod.
I tested it via SAP Gateway Client. It's OK when I remove column luggweight from my SELECT SINGLE * statement. However when I select all columns via SELECT SINGLE *, then it outputs an error
Runtime Error: 'SAPSQL_PARSER_TODO_WARNING'`
<?xml version="1.0" encoding="UTF-8"?>
<error>
<code>SAPSQL_PARSER_TODO_WARNING</code>
<message>Runtime Error: 'SAPSQL_PARSER_TODO_WARNING'.
The OData request processing has been abnormal terminated. If "Runtime Error"
is not initial, launch transaction ST22 for details and analysis. Otherwise,
launch transaction SM21 for system log analysis.</message>
<timestamp>20190905144432</timestamp>
</error>
As you can see the problem is with luggweight field which is of quantity type and its typing method is Type ref to. When I check my BOOKINGSET_GET_ENTITY method via ctr+F2 it outputs a warning:
The database field or the result type of the aggregate function LUGGWEIGHT and the component "LUGGWEIGHT" of "ER_ENTITY" are not compatible.
How should I modify my SELECT query / BOOKINGSET_GET_ENTITY method for it to work?
Luggweight field's typing method should be set to Types (not Type ref to) when creating / modifying zbooking data structure.

How to create an update query with Open Office Base?

I want to create basically an update query on Open Office Base (the same way with Ms ACCESS).
Base does not typically use update queries (but see below). Instead, the easiest way to do an update command is to go to Tools -> SQL. Enter something similar to the following, then press Execute:
UPDATE "Table1" SET "Value" = 'BBB' WHERE ID = 0
The other way is to run the command with a macro. Here is an example using Basic:
Sub UpdateSQL
REM Run an SQL command on a table in LibreOffice Base
Context = CreateUnoService("com.sun.star.sdb.DatabaseContext")
databaseURLOrRegisteredName = "file:///C:/Users/JimStandard/Desktop/New Database.odb"
Db = Context.getByName(databaseURLOrRegisteredName )
Conn = Db.getConnection("","") 'username & password pair - HSQL default blank
Stmt = Conn.createStatement()
'strSQL = "INSERT INTO ""Table1"" (ID,""Value"") VALUES (3,'DDD')"
strSQL = "UPDATE ""Table1"" SET ""Value"" = 'CCC' WHERE ID = 0"
Stmt.executeUpdate(strSQL)
Conn.close()
End Sub
Note that the data can also be modified with a form or by editing the table directly.
Under some circumstances it is possible to create an update query. I couldn't get this to work with the default built-in HSQLDB 1.8 engine, but it worked with MYSQL.
In the Queries section, Create Query in SQL View
Click the toolbar button to Run SQL Command directly.
Enter a command like the following:
update mytable set mycolumn = 'This is some text.' where ID = 59;
Hit F5 to run the query.
It gives an error that The data content could not be loaded, but it still performs the update and changes the data. To get rid of the error, the command needs to return a value. For example, I created this stored procedure in MYSQL:
DELIMITER $$
CREATE PROCEDURE update_val
(
IN id_in INT,
IN newval_in VARCHAR(100)
)
BEGIN
UPDATE test_table SET value = newval_in WHERE id = id_in;
SELECT id, value FROM test_table WHERE id = id_in;
END
$$
DELIMITER ;
Then this query in LibreOffice Base modifies the data without giving any errors:
CALL update_val(2,'HHH')
See also:
https://forum.openoffice.org/en/forum/viewtopic.php?f=5&t=75763
https://forum.openoffice.org/en/forum/viewtopic.php?f=61&t=6655
https://ask.libreoffice.org/en/question/32700/how-to-create-an-update-query-in-base-sql/
Modifying table entries from LibreOffice Base, possible?

How to store xml parser data stored in sqlite database in IOS?

I want to insert xml data in Sqlite database.
For Example :
UPDATE OBJ_ART SET TITLE = '<?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US,fr_FR," default-locale="en_US"><Title language-id="en_US">Distribution Sing EN</Title><Title language-id="fr_FR">Distribution Bâtiment</Title></root>', CONTENT = ‘ABCD’, STRUCT_ID = 12709, DISPLAY_DATE = 1422890 WHERE ART_ID = 12716
can you please any one guide me how to xml parser data to stored in sqlite database,
When working with SQLite, one should generally avoid building SQL statements with stringWithFormat, but rather use SQL like:
UPDATE OBJ_ART SET TITLE = ?, CONTENT = ?, STRUCT_ID = ?, DISPLAY_DATE = ? WHERE ART_ID = ?
Then, one would use the SQLite functions sqlite3_bind_text, sqlite3_bind_int, etc., to bind values to the ? placeholders in the SQL. That will gracefully handle values that happen to have quotation marks within them.
So, call sqlite3_prepare_v2 to prepare the SQL statement, then call sqlite3_bind_xxx for each of the columns, and then sqlite3_step to perform the SQL and, when done, call sqlite3_finalize to release the memory associated with the statement.
Even easier, use a library like FMDB, which greatly simplifies this process.
If want to insert or update XML data in Sqlite. You just follow some rules.
My example :
UPDATE OBJ_ART SET TITLE ='<?xml version=&apos;1.0&apos; encoding=&apos;UTF-8&apos;?><root available-locales="en_US,fr_FR," default-locale="en_US"><Title language-id="en_US">Distribution Sing EN</Title><Title language-id="fr_FR">Distribution Bâtiment</Title></root>', CONTENT = ‘ABCD’, STRUCT_ID = 12709, DISPLAY_DATE = 1422890 WHERE ART_ID = 12716
It's easy way to do. You just replace XML tags to HTML entities.
HTML entities:
1. < ----- replace to ---- <
2. > ----- replace to ---- >
3. " ----- replace to ---- "
4. ' ----- replace to ---- &apos;
I hope it will work. In every where while sending SOAP action also you have to do same thing.

Generic Parsing Error

In a 4D application, I have the following lines of code:
Begin SQL
UPDATE Keys
SET Desc = :$desc,
KeyStamp = :$key_stamp
WHERE KeyTitle = :$key_title
End SQL
When trying to run the code, the following error is displayed:
Generic parsing error. Parsing failed in or around the following
substring interval - ( 16, 23 ) - ... SET Desc = ...
Does anyone see the problem with the code? Keys is not a keyword or anything, is it?
Seems like someone forgot that Desc is a keyword for "descending." The solution is to rename the column and update all references to that column. Otherwise, the column cannot be referenced in SQL.

Resources