Retrieving of PostgreSQL native error code - postgresql

I have installed unixODBC-2.3.1-4.95.x86_64 on my SLES 12 machine and writing some application. But I faced with problem of error handling in PosgreSQL using unixODBC.
To do this I created the following function:
void checkDiag (SQLSMALLINT handleType, SQLHANDLE handle)
{
SQLRETURN rc = SQL_ERROR;
SQLCHAR sqlState[6];
SQLINTEGER nError;
SQLSMALLINT recnum = 0;
SQLCHAR eMsg[SQL_MAX_MESSAGE_LENGTH];
SQLCHAR nativeError[SQL_MAX_MESSAGE_LENGTH];
while (rc != SQL_NO_DATA_FOUND)
{
rc = SQLGetDiagRec (handleType,
handle,
recnum,
sqlState,
&nError,
eMsg,
255,
NULL);
if (rc != SQL_NO_DATA_FOUND)
{
SQLGetDiagField(handleType,
handle,
recnum,
SQL_DIAG_NATIVE,
nativeError,
255,
NULL);
printf("RECNUM %d\n sqlState = %s\n nError = %d\n Error Message %s\n nativeError %s \n",
recnum, sqlState, nError, (char *) eMsg, (char *)nativeError);
}
recnum++;
}
}
I have been trying to use different variants of diagId in SQLGetDiagField : SQL_DIAG_MESSAGE_TEXT, SQL_DIAG_NATIVE, SQL_DIAG_SQLSTATE.
I got everything but not PostgreSQL error Id.
I am constantly getting Postgresql error code id = -1.
So my question is:
Is it possible to get native PostgreSQL error code id using unixODBC API ?
Could you please tell me what I am doing wrong?

I found a solution.
The contents of the config file odbcinst.ini was the following:
[PostgreSQL]
Description=PostgreSQL ODBC driver
Driver=/usr/lib64/unixODBC/libodbcpsql.so
FileUsage=1
After I changed the description of Driver entry in the configuration file I was able to get PostgreSQL native error code.
[PostgreSQL]
Description=PostgreSQL ODBC driver
Driver=/opt/PostgreSQL/psqlODBC/lib/psqlodbcw.so
FileUsage=1
psqlodbcw.so library is supplied by EnterpriseDB PostgreSQL which can be downloaded here https://www.postgresql.org/download/linux/suse/ .
After these modifications I can get native error code. Using the code provided above, the postgres error code value will be written into sqlState.

Related

CreateFile path not found error on a listed USB device with interface

Please help!
I'm trying to open a USB connection to an existing device with a listed active interface.
For that I need to open a file using a device id (path).
But CreateFile() fails with ERROR_PATH_NOT_FOUND (error code 3).
I got the following device ids from the Windows 10 Device Manager on my computer ...
"USB\VID_046D&PID_C534&MI_00\6&168DEF1E&0&0000"
"USB\VID_046D&PID_C534&MI_01\6&168DEF1E&0&0001"
"USB\VID_04F2&PID_B5EE&MI_00\6&237200EE&0&0000"
... and ran the following trivial program using one of them as input to CreateFile():
#include "..\..\test_wconsole\test_wconsole\_wconsole_.h"
#include "conio.h"
int APIENTRY wWinMain(_In_ HINSTANCE hi, _In_opt_ HINSTANCE hpi, _In_ LPWSTR c, _In_ int cs)
{
const WCHAR* path = L"USB\\VID_046D&PID_C534&MI_01\\6&168DEF1E&0&0001";
wcprintf("\nopening file \"%ws\" ... ", path);
HANDLE h_usbdevice = CreateFile
(
path,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
NULL
);
if (h_usbdevice != INVALID_HANDLE_VALUE) wcprintf("done\n"); else wcprintf("error %lu\n", GetLastError());
{ wcprintf("\n\tPress any key to proceed ... "); wcprintf("%i\n\n", _getch()); }
return NULL;
}
Here is a copy of the program’s console output:
opening file "USB\VID_046D&PID_C534&MI_01\6&168DEF1E&0&0001" ... error 3
Press any key to proceed ...
Running the program with Administrator privileges yields the same result. What am I doing wrong?

You have an error in your SQL syntax with tinymce

Hi my script ading system is working perfectly but when i use tinymce plugin so i get this error please help fast if anyone can solve that
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'color: #008000;">dsfdsfsdfsfdfsdfsdfsd", zone1 = "http://www.k' at line 8
this is my adding note code in userpanel
function add_note($note_title, $note_detail, $orient, $c_s, $zone1, $zone2, $zone3, $zone4, $z4_1, $z4_2, $z4_3, $zone5, $z5_1, $z5_2, $z5_3, $zone6, $z6_1, $z6_2, $z6_3, $s_m, $sm_back, $sm_text, $sm_direction, $sm_speed) {
global $db;
$query = 'INSERT into notes VALUES(NULL, "'.date("Y-m-d").'", "'.$note_title.'", "'.$note_detail.'", "'.$orient.'", "'.$c_s.'", "'.$zone1.'", "'.$zone2.'", "'.$zone3.'", "'.$zone4.'", "'.$z4_1.'", "'.$z4_2.'", "'.$z4_3.'", "'.$zone5.'", "'.$z5_1.'", "'.$z5_2.'", "'.$z5_3.'", "'.$zone6.'", "'.$z6_1.'", "'.$z6_2.'", "'.$z6_3.'", "'.$s_m.'", "'.$sm_back.'", "'.$sm_text.'", "'.$sm_direction.'", "'.$sm_speed.'", "'.$_SESSION['user_id'].'")';
$result = $db->query($query) or die($db->error);
return 'Note added successfuly!';
}//add notes ends here.
Here is this link of Full Code of my notes.php
http://pastebin.com/a6sNeXD0
all users Attention here for soloution if they want to use tinymce and they get error like this so they must have to enter there table like this
mysql_real_escape_string($sql_table).
so my code is like this
$query = 'INSERT into notes VALUES(NULL, "'.date("Y-m-d").'", "'.$note_title.'")
so i just add mysql_realescape_string
$query = 'INSERT into notes VALUES(NULL, "'.date("Y-m-d").'", mysql_real_escape_string($notetitle))
and it works but it show me
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established i
so for that you have to add this in before that $query thing :)
$con = mysql_pconnect("localhost","users","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
and you'r done ..... thanks for all help

Erlang and PostgreSQL

I try to execute simple PostgreSQL query with erlang and epgsql.
I do:
{ok, C} = pgsql:connect("localhost", "shk", "qwerty", [{database, "mydb"}]).
>> {ok,<0.34.0>}
Then:
{ok, Cols, Rows} = pgsql:squery(C, "select * from users").
But i got error:
=ERROR REPORT==== 27-Apr-2012::17:58:23 ===
** State machine <0.34.0> terminating
** Last message in was {'EXIT',<0.32.0>,
{{badmatch,
{error,
{error,'ð\236ð¨ð\230ð\221ð\232ð\220',<<"42P01">>,
<<208,190,209,130,208,189,208,190,209,136,208,181,
208,189,208,184,208,181,32,34,109,121,100,98,34,
32,208,189,208,181,32,209,129,209,131,209,137,
208,181,209,129,209,130,208,178,209,131,208,181,
209,130>>,
[{position,<<"15">>}]}}},
[{erl_eval,expr,3}]}}
** When State == ready
** Data == {state,undefined,<0.35.0>,5000,
[{<<"application_name">>,<<>>},
{<<"client_encoding">>,<<"UTF8">>},
{<<"DateStyle">>,<<"ISO, DMY">>},
{<<"integer_datetimes">>,<<"on">>},
{<<"IntervalStyle">>,<<"postgres">>},
{<<"is_superuser">>,<<"off">>},
{<<"server_encoding">>,<<"UTF8">>},
{<<"server_version">>,<<"9.0.7">>},
{<<"session_authorization">>,<<"shk">>},
{<<"standard_conforming_strings">>,<<"off">>},
{<<"TimeZone">>,<<"posixrules">>}],
undefined,undefined,undefined,
{30932,488494147},
{statement,undefined,undefined,undefined},
73}
** Reason for termination =
** {{badmatch,{error,{error,'ð\236ð¨ð\230ð\221ð\232ð\220',<<"42P01">>,
<<208,190,209,130,208,189,208,190,209,136,208,181,
208,189,208,184,208,181,32,34,109,121,100,98,34,
32,208,189,208,181,32,209,129,209,131,209,137,
208,181,209,129,209,130,208,178,209,131,208,181,
209,130>>,
[{position,<<"15">>}]}}},
[{erl_eval,expr,3}]}
What's wrong i do? How can i fix it?
Thank you.
The error string seems to be in russian if I recognize the characters.
To view the response you can use the following command:
io:format("~ts",[<<208,190,209,130,208,189,208,190,209,136,208,181,
208,189,208,184,208,181,32,34,109,121,100,98,34,
32,208,189,208,181,32,209,129,209,131,209,137,
208,181,209,129,209,130,208,178,209,131,208,181,
209,130>>]).
отношение "mydb" не существует
A quick google translate makes me think the database mydb does not exist or you do not have permissions to use it.
try simply doing
Response = pgsql:squery(C, "select * from mydb"),
io:format("~p~n",[Response]).
And see what he is giving back from the server, maybe you have typo or table don't exists etc.
also check this out http://www.erlangatwork.com/2009/01/erlang-and-postgresql.html
From epgsql docs:
Errors
Errors originating from the PostgreSQL backend are returned as {error, #error{}},
see pgsql.hrl for the record definition. epgsql functions may also return
{error, What} where What is one of the following:
{unsupported_auth_method, Method} - required auth method is unsupported
timeout - request timed out
closed - connection was closed
sync_required - error occured and pgsql:sync must be called
Try to include pgsql.hrl, capture the error and print the error message, that should point you to the right direction.

libmemcached - checking if I'm connected

Is there an easy way to check if a given memcached_st* is successfully connected to a memcached server?
I'm connecting via memcached_server_add_with_weight, and it's returning MEMCACHED_SUCCESS when I give it spurious hostnames. Similarly, calling memcached_last_error_errno immediately after the call to memcached_server_add_with_weight gives me MEMCACHED_SUCCESS.
One interesting way to do this is checking the actual socket descriptor.
If libmemcached successfully connected to the server then the socket descriptor is positive, otherwise it is -1.
std::shared_ptr<memcached_st> es (memcached_create (NULL), [](memcached_st* msp) {memcached_free (msp);});
memcached_server_add_with_weight (es.get(), "server1", 9201, 100);
memcached_server_add (es.get(), "server2", 9201);
memcached_server_add (es.get(), "server3", 9201);
memcached_server_fn serverVisitor = [](const memcached_st *ptr, memcached_server_instance_st server, void *context) {
if (server->fd < 0) throw std::runtime_error (std::string ("libmemcached connection to ") + server->hostname + " failed!");
return MEMCACHED_SUCCESS;
};
memcached_server_cursor (es.get(), &serverVisitor, NULL, 1);

Craeting QueueTable in OracleAQ 11.2.0

I have installed Oracle11.2.0(windows,32 bit) and tried to create a queuetable..
(I have granted all permissions for the jmsuser,AQ_ADMINISTRATOR_ROLE,AQ_USER_ROLE,DB_Access).
when try to create a queuetable, Oracle gives following issue;
oracle.jms.AQjmsException: ORA-01017: invalid username/password; logon denied
ORA-06512: at "SYS.DBMS_AQADM", line 81
My sample code is as follows,
createQueue(Session session) {
AQQueueTableProperty qt_prop;
AQQueueTable q_table;
AQjmsDestinationProperty dest_prop;
Queue queue;
qt_prop = new AQQueueTableProperty("SYS.AQ$_JMS_BYTES_MESSAGE");
/* create a queue table */
q_table = ((AQjmsSession) session).createQueueTable("jmsuser", "test_queue_table",
qt_prop);
}
Any idea?
Thanks
I solved this with following setting;
ALTER SYSTEM GLOBAL_TOPIC_ENABLED = FALSE;