I am currently working on a DB2 native stored procedure, working on logging errors. I am logging all of the errors that get raised on another table, and one of the things I am logging is what the stored procedure receives as its parameters.
On one particular stored procedure, one of the parameters is of the data type XML (IN P_FILTERS XML).. What I want to log in the error logging table is just the plaintext of the XML Document.
For example if I pass in XML that looks like this
<xml><Hello value='what is up'></Hello></xml>
I want to put
"<xml><Hello value='what is up'></Hello></xml>" as Varchar(200)
in the error logging table.
I have thouroughly researched this question and am unable to find anything.
I tried to do something like this, but couldn't get it to work
SET V_ERR_XML_TEXT = XMLCAST(XMLQUERY('$m/*'
PASSING P_FILTERS AS "m" RETURNING SEQUENCE) AS VARCHAR(200));
Related
We have some very simple (id INTEGER PRIMARY KEY, data BYTE)-tables that I'm trying to retrieve the data from, but seem to run into some kind of data corruption. When accessing or retrieving the data-column e.g. via SELECT data FROM foobar WHERE id = 42 or SELECT LENGTH(data) FROM foo WHERE id = 42 I get
[HY000] [Informix][Informix ODBC Driver][Informix]Text/Byte subscript error. (-607) (SQLFetch)
which is obviously weird, as no byte subscript operator is used. It rather seems to me Informix is running into some kind of data corruption issue and is unable to retrieve the underlying BLOB. The query works if I explicitly exclude the offending row, so SELECT SUM(LENGTH(data)) FROM foo fails with the above error, while SELECT SUM(LENGTH(data)) FROM foo WHERE id NOT IN (42,...) succeeds.
For other rows, I retrieve an error
[01004] [Informix][Informix ODBC Driver]Data truncated. (-11003) (SQLGetData)
which also can only be mitigated by (finding and) excluding the offending row via their primary key.
First of all, is there a way to tell if this is a driver/odbc error or if the underlying data is actually corrupted? Is there a way to check the tables for data corruption, instead of running into this kind of problem one by one?
This is IBM Informix Dynamic Server Version 14.10.FC5WE
It sounds to me like running the same query, but using different tool or method, would give you an idea if it's the driver or the data itself.
If the data is corrupted, you can use the following to confirm the checksum value and identify:
CHECKSUM TABLE foobar;
Also, obviously updating the driver version is given, have you tried that?
Windows 10, Access 2016
I am moving a very small database (14 tables and 40-50 stored procedures) from SQL Server to Access. I have tried to recreate the stored procedures from code using an OLEDB command object. This is a sample of a CommandText…
CREATE PROCEDURE DeleteOrderDetailByOrderID
([#ID] int)
AS
DELETE FROM OrderDetails
WHERE (OrderID = #ID);
I get an error message that the Data Type of #ID is incorrect. It is not. When I remove the brackets from #ID all is forgiven and the code runs. However, Access strips the # from #ID in the parameter section (not in the Where clause). I have had to go into Access and manually correct this. I do not like the idea of going through almost 5000 lines of code to correct parameter names in my program. I thought I could use the direct approach by pasting the SQL directly into Access but I get an error with this route saying syntax error in CREATE TABLE and it highlights the word PROCEDURE. This leads me to believe that you cannot use CREATE PROCEDURE directly in Access. Is this true? Is there another approach that I am missing?
You are missing, that T-SQL of SQL Server is not Access SQL.
Access has UDFs - user defined functions - that can be used in queries also, but that is VBA code.
If you just need a single-user file based database to hold your data, you may get away with the SQL Server Compact Edition which supports a subset of T-SQL.
I have report deployed on a SQL Server Reporting server. It has one multivalue parameter called 'Names' as a input for stored procedure which fetch data to display the result. In URL, I am adding all values selected for multivalue parameter are concatenating with '&' character.
I need to store this URL for further uses as a bookmark in my browser which is also working fine. Problem occurs when over a time one of the values for that parameter gets missing from the database then report comes blank.
Some points I would like to clear here:
Stored procedure is working fine even if some values are missing.
I could figure out that this might be because of that value is not present in the dropdown of 'Names' so it is unable to assign it before running the stored procedure. As a solution to this problem I tried to hide this parameter from report by clearing prompt box for 'Names', but I now get
The ''Names'' parameter is missing a value
When you upload the report (.rdl) into reporting server, make sure "Name" parameter has a default value, this way the stored procedure is able to get the default value even if the link is missing the "Name" parameter
I have a datetime value which comes from the API in this format: 2015-07-07T17:30:00+00:00. I simply want to split it up between the date and time values at this point. I am not using an Active Record model and I prefer not to use an sql database if I can.
The way I have set up the app means that the value is "stored" like this in my view: #search.dining_date_and_time
I have tried two approaches to solving this problem:
Manually based on this previous stackoverflow question from 2012: Using multiple input fields for one attribute - but the error I get is the attribute is "nil" even though I put a "try"
Using this gem, https://github.com/ccallebs/split_date_time which is a bit more recent and seems to be a more elegant solution, but after closely following the doc, I get this error, saying my Search model is not initalized and there is no method: undefined method dining_date' for #<Search not initialized>
This is when instead I put #search.dining_date in the view, which seems to be the equivalent of the doc's example (its not that clear). The doc also says the method will be automatically generated.
Do I need to alter my model so I receive the data from the API in another way? ie. not get the variable back as #search.dining_date_and_time from the Search model for any of this to work?
Do I need an Active Record model so that before_filter or before_save logic works - so i can (re)concatenate after splitting so the data is sent back to the API in a format it understands. Can I avoid this - it seems a bit of overkill to restructure the whole app and put in a full database just so I can split and join date/time as needed.
Happy to provide further details, code snippets if required.
As I am not using a conventional Rails DB like MySql Lite or Postgresql, I found that the best solution to the problem was by using this jQuery date Format plugin: https://github.com/phstc/jquery-dateFormat to split the date and time values for display when I get the data back from the API.
The Github docs were not too expansive, but once I put the simply put the library file in my Rails javascript assets folder, I just had to write a few lines of jQuery to get the result and format I wanted:
$(function() {
var rawDateTime = $('#searchDiningDateTime').html();
// console.log(rawDateTime);
var cleanDate = $.format.date(rawDateTime, "ddd, dd/MM/yyyy");
// console.log(cleanDate);
$('#searchDiningDateTime').html(cleanDate);
var cleanTime = $.format.date(rawDateTime, "HH:mm");
// console.log(cleanTime);
$('#searchTime').html(cleanTime);
});
Next challenge: rejoin the values on submit, so the API can read the data by sending/receiving a valid request/response. (The values can't be split like this when sent to the remote service).
I would like to create a generic logging solution for my stored procedures, allowing me to log the values of input parameters. Currently I am doing this more or less by hand and I am very unhappy with this approach. Ideally, I would like to say something like the following:
"given my spid, what are my input parameters and their values?"
This is the same information exposed to me when I run SQL Profiler -- the stored procedure's name, all input params and all input VALUES are listed for me. How can I get my hands on these values from within a stored procedure?
Thanks;
Duncan
That is going to be difficult to do within a stored procedure. SQL profiler runs under a different SPID and runs a statement like this to capture the other users statements:
DECLARE #handle VARBINARY(64)
SELECT #handle = sql_handle from sys.sysprocesses where spid = #SPID
SELECT text FROM sys.dm_exec_sql_text(#handle)
The problem is if you run this in a stored proc for the current SPID all your going to get back is the statement above. I don't believe SQL server provides a T-SQL construct to execute a batch under a different SPID. I suppose you could write a .Net dll stored procedure that executes a batch on a different connection. to do that sort of thing but it may be more trouble than it's worth.