I had made connector/ODBC successfully,then I write some code:
SQLHENV henv;
SQLHDBC phdbc;
SQLRETURN retcode;
retcode = SQLAllocEnv(&henv);
retcode = SQLAllocConnect(henv,&phdbc);
if(retcode == SQL_SUCCESS)
{
char *a="cc_mysql";
char *b="chen1991";
retcode = SQLConnect(phdbc,(SQLCHAR*)a,SQL_NTS,(SQLCHAR*)b,SQL_NTS,(SQLCHAR*)b,SQL_NTS);
}
but I failed to connect. I debug it and found that the SQLAllocConnect return true ,but SQLConnect return -1,I can't understand what happened.
What happened is your call to SQLConnect failed and you need to call SQLError to get the error back. I'd just be guessing but may be the DSN cc_mysql does not exist or your username/password are invalid, or mysql does not allow that user to access it etc.
BTW, you should really be writing at least ODBC 3 applications these days and to do that you should be calling SQLAllocHandle, SQLSetEnvAttr (to set ODBC behavior), SQLDriverConnect and SQLGetDiagRec.
Related
I'm using java TinyB to connect to a TimeFlip device with Bluetooth LE.
When trying to write to the Descriptor of the Facet Characteristic to recieve notifications I always get the error:
Exception in thread "main" tinyb.BluetoothException: GDBus.Error:org.bluez.Error.NotPermitted: Write not permitted
But when I write to the same Descriptor using gatttool it works and i get the notifications.
BluetoothGattService timeFlipService = device.find("f1196f50-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
BluetoothGattCharacteristic facets = timeFlipService.find("f1196f52-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
BluetoothGattDescriptor facetsConfig = facets.find("00002902-0000-1000-8000-00805f9b34fb", Duration.ofSeconds(5)); // like this ==> always null, custom method works???
if(!login(timeFlipService)) {log.error("login to TimeFlip failed");}
try{
byte[] enableNotifications = {0x01, 0x00};
facetsConfig.writeValue(enableNotifications); //when facesConfig assigned with custom method throws write not permitted error
facets.enableValueNotifications(new FacetNotification());
}
catch(NullPointerException e){
log.error("NullPointerException in " + (facets == null ? "facet characteristic" : "facet descriptor"));
}
catch(BluetoothException b){
log.error(b.getMessage());
}
}
The mentioned "custom method" just gets all Descriptor from a characteristic and returns the one matching a given uuid, as the find() method times out every time.
In Bluez you are supposed to use StartNotify to turn on notifications or indications. Bluez will do the writing of the descriptor for you but if you try to do it yourself it indeed gives an error.
I have a runnable jar for a java8 program which uses sqlite-jdbc 3.14.2. It works fine on windows 10 and ubuntu. i.e. i can query stuff on these platforms on all the tables. However, when i run it on FreeBSD 10.3-releasep4, it gives me the following error when i run queries on all the tables.
[SQLITE_IOERR_LOCK] I/O error in the advisory file locking logic (disk I/O error) on FreeBSD 10.3-release
Please advise a workaround or solution.
Same issue exists with 3.16.1
So I finally found out what was wrong. It was an NFS mounted volume that was causing the problem. With DB file on local file system, it works like a charm.
If anyone is coming to this question at later time, this error can be reproduced by first creating or opening a DB with WAL journalling mode, writing something, then closing the DB and trying to open it again in read-only mode with journalling off. This unit test will reproduce the error:
#Test
public void mixJournalingModesFailureTest()
{
File tempDb = File.createTempFile("tempdbtest", ".db");
tempDb.deleteOnExit();
// Open a temp DB in RW mode with WAL journalling
String url = "jdbc:sqlite:" + tempDb.getAbsolutePath();
SQLiteConfig config = new SQLiteConfig();
// Ser read-write with WAL journalling
config.setJournalMode( SQLiteConfig.JournalMode.WAL );
config.setReadOnly( false );
Properties props = config.toProperties();
Connection conn = DriverManager.getConnection( url, props );
// Write something
try ( Statement statement = conn.createStatement() )
{
statement.execute( "CREATE TABLE test (words text)" );
}
// Close the DB
conn.close();
// Open the DB again but with journalling off and in read-only mode
config.setJournalMode( SQLiteConfig.JournalMode.OFF );
config.setReadOnly( true );
props = config.toProperties();
try
{
// This will throw the SQLITE_IOERR_LOCK advisory lock exception
DriverManager.getConnection( url, props );
fail( "Should throw advisory lock exception" );
}
catch ( SQLException ignore ) {}
}
I am trying to make a localhosted WordPress site use the ODBC connections I use for business analytics.
I made a plugin and am trying to reference the functions in shortcode (because this is the only way I know to do this).
Below is my code:
$dsn = '****';
$user = '****';
$pw = '****';
$connect = odbc_connect($dsn, $user, $pw);
if ($connect == true){
echo '<br> connected <br>';
} else{
echo '<br> not connected <br>';
}
From what I understand this should be testing to see if the connection is open and it gives me an error (posted below). My big question is if I need to install an ODBC driver on the site to make it able to perform the connection.
If so, where do I find this?
I use four MS SQL servers on the domain and would also like to be able to work with access and excel.
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
in
C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php:54
Stack trace:
#0 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(326):HPM_API_E2('', '', 'HPM_API_E2')
#1 [internal function]: do_shortcode_tag(Array)
#2 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(223):preg_replace_callback('/\\[(\\[?)(HPM_AP...','do_shortcode_ta...','[HPM_API_E2]\n[H...')
#3 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\plugin.php(235):do_shortcode('[HPM_API_E2]\n[H...')
#4 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\post-template.php(240):apply_filters('the_content', '[HPM_API_E2]\n[H...')
#5 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\themes\generatepress\content-page.php(24):the_content()
#6 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\template.php(574):require('C:\\Bitnami\\word...')
#7 C:\Bitnam in C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php on line 54
$connect will never be true. This is because odbc_connect() does not return a boolean when it succeeds. It returns a connection IDinstead.
If the connection fails it will return an error or false, so it will end up in the else. If it succeeds it contains an ID and should evaluate to true.
if ($connect){
echo '<br> connected <br>';
} else{
echo '<br> not connected <br>';
}
Edit:
You've just added the error message you're getting. That error means the function is not available, and that will most likely be caused by the missing ODBC drivers for your php client. Someone else made this post on how to install this:
Call to undefined function odbc_connect() message while connecting SAP Hana database
I hope this helps.
I'm trying to connect to a D-Bus signal this way:
bool result = QDBusConnection::systemBus().connect(
"foo.bar", // service
"/foo/bar", // path
"foo.bar", // interface
"SignalSomething",
this,
SLOT(SignalSomethingSlot()));
if( !result )
{
// Why!?
}
QDBusConnection::connect() returns a boolean, how do I get extended error information? If a check QDBusConnection::lastError() it returns no useful information (as QDBusError::isValid() is false).
I had the same issue and it turned out that the slot I connected to had the wrong parameter types. They must match according to Qt's documentation and it looks like connect() verifies that, despite not explicitly mentioned.
Warning: The signal will only be delivered to the slot if the parameters match.
I suggest d-feet to list signals and check their parameter types. dbus-monitor does list signals, paths and such too, but not always the exact type of parameters.
One important observation though: I fixed the issue in my particular case by using different slot parameters than the actual signal has!
I wanted to connect to a com.ubuntu.Upstart0_6 signal mentioned here to detect when the screen in Ubuntu is locked/unlocked. dbusmonitor prints the following and d-feet shows parameters (String, Array of [String])
// dbusmonitor output
signal time=1529077633.579984 sender=:1.0 -> destination=(null destination) serial=809 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=EventEmitted
string "desktop-unlock"
array [
]
Hence the signal should be of type
void screenLockChangedUbuntu(QString event, QVector<QString> args) // connect() -> false
This however made connect() return false. The solution was to remove the array parameter from the slot:
void screenLockChangedUbuntu(QString event) // works
I am aware that the array parameter was always empty, but I cannot explain why it only worked when removing it.
You could try these tricks:
1) Set QDBUS_DEBUG environment variable before running your application.
export QDBUS_DEBUG=1
2) Start dbus-monitor to see what's happening on the bus. You may need to set a global policy to be able to eavesdrop system bus depending on your distro.
Update:
Are you sure connecting to the system bus succeeded? If it fails you should probably check system.conf policy and possibly create own conf in system.d. This post might be helpful.
You could first connect to the system bus with QDBusConnection::connectToBus and check if it succeeded with QDBusConnection::isConnected. Only after that you try to connect to the signal and check if that succeeded.
QDBusConnection bus = QDBusConnection::connectToBus(QDBusConnection::systemBus, myConnectionName);
if (bus.isConnected())
{
if(!bus.connect( ... ))
{
// Connecting to signal failed
}
}
else
{
// Connecting to system bus failed
}
My code, which tries to emulate an R shell via C++, allows a user to send R commands over a tcp connection which are then passed to the R instance through the RInside::parseEvalQ function, during runtime. I have to be able to handle badly formatted commands. Whenever a bad command is given as an argument to parseEvalQ I catch the runtime error thrown (looking at RInside.cpp my specific error is flagged with 'PARSE_ERROR' 'status' within the parseEval(const string&, SEXP) function), what() gives a "St9exception" exception.
I have two problems, the first more pressing than the second:
1a . After an initial Parse Error any subsequent call to parseEvalQ results in another Parse Error even if the argument is valid. Is the embedded R instance being corrupted in some way by the parse error?
1b . The RInside documentation recommends using Rcpp::Evaluator::run to handle R exceptions in C++ (which I suspect are being thrown somewhere within the R instance during the call to parseEval(const string&, SEXP), before it returns the error status 'PARSE_ERROR'). I have experimented trying to use this but can find no examples on the web of how to practically use Rcpp::Evaluator::run.
2 . In my program I re-route stdout and stderr (at C++ level) to the file descriptor of my tcp connection, any error messages from the RInside instance get sent to the console, however regular output does not. I send RInside the command 'sink(stderr(), type="output")' in an effort to re-route stdout to stderr (as stderr appears to be showing up in my console) but regular output is still not shown. 'print(command)' works but i'd like a cleaner way of passing stdout straight to the console as in a normal R shell.
Any help and/or thoughts would be much appreciated. A distilled version of my code is shown below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using namespace std;
string request_cpp;
ostringstream oss;
int read(FILE* tcp_fd)
{
/* function to read input from FILE* into the 'request_cpp' string */
}
int write(FILE* tcp_fd, const string& response)
{
/* function to write a string to FILE* */
}
int main(int argc, char* argv[])
{
// create RInside object
RInside R(argc,argv);
//socket
int sd = socket(PF_INET, SOCK_STREAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(40650);
// set and accept connection on socket
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
bind(sd,(struct sockaddr*)&addr, sizeof(addr));
listen(sd,1);
int sd_i = accept(sd, 0, 0);
//re-route stdout and stderr to socket
close(1);
dup(sd_i);
close(2);
dup(sd_i);
// open read/write file descriptor to socket
FILE* fp = fdopen(sd_i,"r+");
// emulate R prompt
write(fp,"> ");
// (attempt to) redirect R's stdout to stderr
R.parseEvalQ("sink(stderr(),type=\"output\");");
// read from socket and pass commands to RInside
while( read(fp) )
{
try
{
// skip empty input
if(request_cpp == "")
{
write(fp, "> ");
continue;
}
else if(request_cpp == "q()")
{
break;
}
else
{
// clear string stream
oss.str("");
// wrap command in try
oss << "try(" << request_cpp << ");" << endl;
// send command
R.parseEvalQ(oss.str());
}
}
catch(exception e)
{
// print exception to console
write(fp, e.what());
}
write(fp, "> ");
}
fclose(fp);
close(sd_i);
exit(0);
}
I missed this weeks ago as you didn't use the 'r' tag.
Seems like you are re-implementing Simon's trusted rserver. Why not use that directly?
Otherwise, for Rcpp question, consider asking on our rcpp-devel list.