I'm trying to determine if a transaction fails from the application. How can this be done?
Further, is it possible to determine where a transaction failed, such as particular write that violates a constraint?
In regular libpq, you would:
Test the result of a query with PQresultStatus
PQresultErrorField(thePgResult, PG_DIAG_SQLSTATE) to get the SQLSTATE
Use PQerrorMessage to get the error message for display to the user. do not rely on parsing this in your application, instead use the SQLSTATE, and the other fields in the result struct.
See connection status functions, libpq exec functions and the rest of the libpq documentation.
Related: How to get the sql state from libpq?
I have no experience with libpqxx, but I would expect it to wrap SQL errors into C++ exceptions with fields for the SQLState etc. See the getting started guide for libpqxx and the libpqxx exception classes reference.
This mailing list post and the replies in the thread will also be of interest, but be aware it's from 2007, and since then PostgreSQL has been extended to report more information in PQresult, like PG_DIAG_CONSTRAINT_NAME. No idea if libpqxx has been extended to take advantage of that, but you might be able to unwrap the exception to get an underlying PQresult if not.
There is, AFAIK, no way to get the actual value causing the issue except by showing the user the full error message. It'd be nice to change that.
Related
I am using saxon xslt processor and python script to perform xslt transformations. I want to add exception handling to the python script. The saxon processor has inbuilt exceptions which are raised with codes (eg., SXXP003) etc. These error messages are displayed in the console because i am executing saxon files using batch file. The issue is that the saxon errors are not being written to traceback stack in python because of which i am unable to retrieve the error message. please provide a solution for the problem. I want to display the saxon error in the try except of python.
Regards
Anshul Mittal
Python has a number of different ways of invoking external programs via their command line interface: check whether the method you are using has any way of redirecting the System.err output stream. (I don't know Python so I can't advise on that aspect). If you can find a way to do this, then you can try to parse the error messages and extract the error codes.
A different approach, which might perform better and would give you more control (but which might involve more effort to configure correctly), would be to use the new Saxon/C product and invoke it via its C APIs, instead of invoking the Java product via its command-line interface.
In addition to Mike's reply, a python interface for Saxon/C is in development and worth a look:
https://github.com/ajelenak/pysaxon
I'm trying to set up an error detection system in c++ when doing a mysql_query, to check whether the query failed and if so try again (I'm using the mysql libray for Linux). The function mysql_query returns an int which is set to zero for success, and non-zero if failed (the error numbers are available at https://dev.mysql.com/doc/refman/5.0/en/mysql-query.html).
My first problem is that mysql_query only returns 0 or 1 for me, and this would be fine until I try to update a database entry with a similar content to what's already in the database. It also returns an error for that, which is fine on the principle, but as I can't differentiate it from an normal error, my current error detection system would try to repeat the query until it stops returning an error, which never happens. You'll tell me I could check what's in the DB first and then compare it to what I try to update before doing the query, and you would be right, but the code is already very complex and adding this level of complexity on the top would take quite some time.
So I'm wondering if there is a simpler answer to that? Thanks
Like #Mat wrote just use mysql_errno() (see Mysql Docs)
It returns 0 for success or an error code for errors.
Just so you guys know where this error actually came from, if you ever have the same.
I repetitively had mysql errors 2013 and 2006 when performing queries from different threads at the same time, but only after running a certain number of requests. I tried pretty much everything explained here.
Apparently for some reason the connection crashes and I can't do much to avoid it. The only thing that worked for me is to enable automatic reconnect using mysql_options and the option MYSQL_OPT_RECONNECT. It seems like a work around, more than a real fix, but at least my program doesn't crash now!
I am using SQL Server Compact Edition.
One of the column size of my table is more than 500.
When I am Selecting from this table I am getting this error in visual studio:
multiple steps oledb operation generated
How can I avoid this error?
This may happen when you pass an unexpected value in one of your DB operation (say you pass NULL to a non-NULL field for example).
I would expect the error message to be longer and more informative (did you truncate it ?). In the current situation, that's pretty much all we can say about it.
A quick google search gave me that link which may help.
You know GetActiveObject just can get the COM object of the first opened application. How to get all running objects? e.g. I run two Excel applications, How to get the two Excel objects in C++ code?
There is usually only one instance of Excel as Hans says. If there is only one instance it will refuse to open the same document twice.
But there may be more than one, typically if a second has been started explicitly. In that case it may open the same file (though you will get a warning about locking).
They may or may not both appear in the Running Object Table. Use ROT viewer or something like this to determine whether that is the case:
http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/ccccc9bd-f21a-4f74-a3f0-64a594fa1b16
Finally you might consider using Microsoft UI Automation:
http://msdn.microsoft.com/en-us/library/ms753388.aspx
http://msdn.microsoft.com/en-us/library/ms726294(VS.85).aspx
I have seen some posts that mention the xmlserializer being called at runtime in .Net.
I have a sharepoint web-part that calls a webservice to retrieve data, and then is supposed to display that data on the web-part. But I get this error:
System.Runtime.InteropServices.ExternalException: Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe" /noconfig /fullpaths #"C:\Users\my_deploy_spFarm_user\AppData\Local\Temp\OICE_356C17F3-2ED2-423C-8BBE-CA5C05740FD7.0\eelwfhnn.cmdline
Now the posts I have read here, state that the problem is that the compiler is trying to to create an XML serialization assembly on the fly, but does not have privilege to do so.
I have seen some suggestions to use the post-build events to create this XML Serialization Assembly at Compile-time. However I am not sure of how to do that, and also I am not sure if this assemply would get included in the .wsp package?
I'd take a good look at whether you really want the full, automatically generated serializer, or whether you just want to emit/parse some relatively straightforward XML - if the latter, you'll solve this problem by not using stuff that needs generated code, i.e. use the XmlReader/XmlWriter directly.
This link has the basic command to create the pre-compiled serializers.