PostgreSQL error codes are not returned in int? - postgresql

I have my java program connected to postgresql. I want to retrieve the error codes for sqlexception. I found the error code for postgresql here.
But Java's SQLException contains only methods for error codes returned as int getErrorCode()
But the error codes in the link are not of the type int. Where can I get the int error codes for postgresql?`

I think that getSQLState() is what you are looking for:
http://docs.oracle.com/javase/6/docs/api/java/sql/SQLException.html#getSQLState()

Related

Is there a more advance way to handle Go Entgo postgreSQL error handling?

So I'm developing a API using Go together with ORM package Entgo and Postgres. Is there a way to handle the errors same or similar way as they are solved in pg package where I have all needed information why query failed?
All I found in ent go are this methods but they only return bool
ent.IsNotFound(err)
ent.IsConstraintError(err)
ent.IsNotLoaded(err)
ent.IsValidationError(err)
It would be great to have something similar like pg.Error:
type Error struct {
Severity string
Code ErrorCode
Message string
Detail string
Hint string
Position string
InternalPosition string
InternalQuery string
Where string
Schema string
Table string
Column string
DataTypeName string
Constraint string
File string
Line string
Routine string
}
So I asked this same question on package repo and this is the answer I got from repo Maintainer.
Ent wraps or returns the underlying driver errors. So, you can either use type-assertion or errors.Is/errors.As helpers to extract these types.
See examples in our integration-test:
https://github.com/ent/ent/blob/60e0328/entc/integration/integration_test.go#L1845-L1858
https://github.com/ent/ent/blob/60e0328/entc/integration/integration_test.go#L423

The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007

Am facing Issue with date format while running Informatica mapping with database db2.
Effective date coming from input is "2020-03-17 00:00:00.000000000".
But on passing to stored procedure I called in mapping it is reading it in format "03/17/2020 00:00:00.000000000" which causes Informatica to throw the following exception into the Informatica session logs.
Severity Timestamp Node Thread Message Code Message
ERROR 4/2/2020 11:53:34 AM ecrmqetl TRANSF_1_1_1 CMN_1022 Database driver error...
CMN_1022 [ [IBM][CLI Driver][DB2/AIX64] SQL0180N The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007 sqlstate = 22007
Database driver error...
Function Name : ExecuteSP
Native error code = -180
Database driver error...
Function Name : ExecuteSP
Native error code = -180]
Any help is much appreciated.
Try to convert input string into expected date type format .

JasperReports: report parameter as an argument for message bundle lookup

How to look up a particular internationalized property based on a report parameter?
This works, but is static:
$R{some_literal_string}
This works too, but is not internationalized:
$P{key_to_parameters_map_element}
What I need is:
$R{$P{key_to_parameters_map_element}}
Unfortunately, I get a pile of error messages:
Caused by: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Syntax error on token "}", delete this token
value = str("$P{key_to_parameters_map_element")}; //$JR_EXPR_ID=13$
This doesn't change anything:
$R{$P{key_to_parameters_map_element}.toString()}
Is this possible at all?
It's
str($P{key_to_parameters_map_element})
Quite intuitive, isn't it?

Decode HResult = -2147467259

Can someone help me decode this HResult? What does it mean? I know the negative stands for a failure. How about the rest of the 10 bits?
I referenced MSDN HResult article here, but I am not sure how to determine what my facility and code bits are.
More info:
_message: "External component has thrown an exception."
Data: {System.Collections.ListDictionaryInternal}
I'll show you how to do it. Paste the negative number into Calculator (Windows) in programmer mode "Dec" setting. Then convert to "Hex" setting. You get the number: FFFFFFFF80004005. The error is 80004005 which is:
0x80004005
E_FAIL
Unspecified
Unfortunately the provider of the function that gave you this error did not categorize the error.
Useful links:
MSDN - HRESULT Format
MSDN - HRESULT Error List
Another way to do it is as follows. An HRESULT should contain a System Error Code in its first 32 bits. Using an AND operation will retrieve the error code from the HRESULT:
int result = (-2147467259 & 0xFFFF)
result is 16389, which is not a part of the System Error Codes list, and as a result, is unspecified.
Print it as an hexadecimal number, then, use for instance, VisualStudio ErrorLookup, to get the message.
-2147467259 in decimal is 80004005 in hexadecimal (usually rendered as 0x80004005). That's "E_FAIL (Unspecified error)" in Win32.
Not a very helpful error code, but maybe it'll get you a half-step closer to a solution.

How to get the sql state from libpq?

I program with libpq.so. I want to get the error code which is called sql state in SQL Standard.How should I get this in my c code?
The obvious Google search for libpq get sqlstate finds the libpq-exec documentation. Searching that for SQLSTATE finds PG_DIAG_SQLSTATE in the PQresultErrorField section.
Thus, you can see that you can call PQresultErrorField(thePgResult, PG_DIAG_SQLSTATE) to get the SQLSTATE.
This is just addition I can not leave in form of comment due to reputation reasons.
Note that you can not portably get SQLSTATE for errors that can occur during PQconnectdb. In theory, you can read pg_conn (internal struct) field last_sqlstate which contains correct value.
For example, if you try to connect with invalid login/password, it will give you 28P01. For wrong database it will contain 3D000.
I wish they defined publically available getter for this field.
You can check this one as well:
libpq: How to get the error code after a failed PGconn connection