dlopen load library correct,but run the program,the result is incorrect - mysql

I use dlopen, dlsym load library function. When I run the program, I met this problem:
use dlopen load function, call the function correct but the result is incorrect
don't use dlopen and call the function directly,the result is correct
How can I find the problem?
Example:
void *dl_handle = NULL;
char *error = NULL;
/* Open the shared object */
dl_handle = dlopen(pLibraryName, RTLD_LAZY );
if (!dl_handle)
{
return -1
}
char* error = NULL;
pFunc = dlsym( dlHandle, "mysql_rollback");
error = dlerror();
if (error != NULL)\
{
return -1
}

Related

API call with invalid database connection pointer & misuse error when updating values in table - objective c application

I am working on a messaging iOS application and below is the code to update a table when a new message is received for a chat:
- (BOOL) updateInfoForChat:(Chat*)chat {
BOOL success;
int code = 0;
if (!dbOpen && dbConnection != NULL) {
if (sqlite3_open_v2([[DatabaseManager databasePath] UTF8String], &dbConnection, SQLITE_OPEN_READWRITE|SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {
dbOpen = YES;
const char* key = [[self getDBKey] UTF8String];
sqlite3_key(dbConnection, key, (int)strlen(key));
chat.lastMessage = [chat.lastMessage stringByReplacingOccurrencesOfString:#"\"" withString:#"%27"];
char *errMsg;
NSString *insertSQL = [NSString stringWithFormat:#"UPDATE Chats SET "
"lastMessageTime = %f, lastMessageText = \"%#\", canReply = \"%#\", isArchived = \"%#\" WHERE chatRoomId = \"%#\" AND lastMessageTime <= (SELECT messageTime FROM Messages WHERE chatRoomId = \"%#\" ORDER BY messageTime DESC LIMIT 1)",
chat.lastMsgTime, chat.lastMessage , chat.canReply ? #"True" : #"False" , chat.isArchived ? #"True" : #"False", chat.chatRoomID, chat.chatRoomID];
const char *sql_stmt = [insertSQL UTF8String];
code = (sqlite3_exec(dbConnection, sql_stmt, NULL, NULL, &errMsg));
if (code == SQLITE_OK) {
//commenting this out as this makes the logs very noisy
}
else {
NSLog(#"This method did not get executed with error: %s",sqlite3_errmsg(dbConnection));
}
sqlite3_close_v2(dbConnection);
dbOpen = NO;
}
else {
NSLog(#"This method did not get executed with error: %s",sqlite3_errmsg(dbConnection));
}
}
return success = (code == SQLITE_OK);
}
Having received messages in a couple of chats, I get the errors below when application hits this code:
API call with invalid database connection pointer
misuse at line 133563 of [d24547a13b]
This method did not get executed with error: bad parameter or other API misuse
Can someone suggest where the issue could be coming from?

Mysql error - Commands out of sync; you can't run this command now - postman error - codeigniter

My application is in codeigniter framework , in my application I written a rest api function. When I call that function from postman i got an error:
ERROR: Commands out of sync; you can't run this command now
Firstly I call a model function for invoking a stored procedure and then i calls a normal query .The provided codes are representational purpose only.
My API function is :(All are dummy functions)
public function products_get()
{
$cat_id = $this->input->get('cat_id');
$sub_categories = $this->Products_model->fetch_cate($cat_id); //dummy functions
$products = $this->Products_model->get_pdts($cat_id);
$data['status'] = TRUE;
$data['message'] = 'success';
$data['categories'] = $products;
$this->set_response($data, self::HTTP_OK);
}
My model function is:
public function fetch_cate($cat_id)
{
$query = $this->db->query("CALL getSubcategory($cat_id)");
return $query->result();
}
public function get_pdts()
{
return $this->db->get('category_product')->result();
}
I find a decent solution from internet just posting after this question :
Add this line of code ->
mysqli_next_result( $this->db->conn_id );
After the stored procedure call ->
$query = $this->db->query("CALL getSubcategory($cat_id)");
mysqli_next_result( $this->db->conn_id ); //add this line of code

Calling a function inside a function - converting AS2 to AS3

I currently have some code from here (https://github.com/jmhnilbog/Nilbog-Lib-AS2/blob/master/mx/mx/remoting/NetServiceProxy.as) which converts a function into a function. This code is shown below:
private var _allowRes:Boolean= false;
function __resolve( methodName:String ):Function {
if( _allowRes ) {
var f = function() :Object {
// did the user give a default client when he created this NetServiceProxy?
if (this.client != null) {
// Yes. Let's create a responder object.
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
else {
if (typeof(arguments[0].onResult) != "function") {
mx.remoting.NetServices.trace("NetServices", "warning", 3, "There is no defaultResponder, and no responder was given in call to " + methodName);
arguments.unshift(new NetServiceProxyResponder(this, methodName));
}
}
if(typeof(this.serviceName) == "function")
this.serviceName = this.servicename;
arguments.unshift(this.serviceName + "." + methodName);
return( this.nc.call.apply(this.nc, arguments));
};
return f;
}
else {
return null;
}
}
Basically what the code is designed to do is return a new function (returned as f) which performs the correct server operates. However, if I try and use this syntax in AS3, I get the following two errors:
Error: Syntax error: expecting semicolon before colon.
Error: Syntax error: else is unexpected.
How would I go about doing this? I know this is someone else's code, but I am trying to get the old AS1/2 mx.remoting functionality working in AS3. Cheers.

C mysql_num_rows() Segmentation fault

I'm trying to execute MySQL query in C, however I get a Segmentation fault while calling mysql_num_rows().
Here's the code I'm using:
char *username = "test#mail.com";
char *password = "pass";
char query[1000];
int len;
char *q = "SELECT * FROM Users WHERE `Email` = '%s' AND `Password` = '%s'";
len = snprintf(query, strlen(q) + strlen(username) + strlen(password), q, username, password);
MYSQL_RES *result;
if (db_query(query, result))
{
if (result != NULL)
{
int test_count = mysql_num_rows(result);
printf("%d\n", test_count);
}
}
else
{
printf("Query error\n");
}
And here is the db_query() function:
bool db_query(const char *query, MYSQL_RES *result)
{
if (mysql_query(db_connection, query))
{
printf("mysql_query(): Error %u: %s\n", mysql_errno(db_connection), mysql_error(db_connection));
return false;
}
if (!(result = mysql_store_result(db_connection)))
{
printf("mysql_store_result(): Error %u: %s\n", mysql_errno(db_connection), mysql_error(db_connection));
return false;
}
return true;
}
I've tested the query and the problem isn't there, the connection is initiated too. Any ideas?
Thanks!
Your problem is here, in the db_query function:
if (!(result = mysql_store_result(db_connection)))
The assignment to result has no visible effect in the function's caller - you're passing a pointer by value, changing the value of result in the callee doesn't do anything to result in the caller.
You need to change your function to take a pointer-to-pointer, and adapt the call site and the db_query function.
bool db_query(const char *query, MYSQL_RES **result)
{
...
if (!(*result = mysql_store_result(db_connection)))
...
}
Any changes to result in your db_query function are not reflected back to the caller, hence it will still contain the arbitrary value it had when it was created (as an auto variable with no initialisation.
If you want to change the value and have it reflected back, you should pass a double pointer to it then dereference the double pointer to get at the actual value.
Even better would be to return the result value and use its NULL/non-NULL status for a success code rather than returning true/false.

Graniteds - ejb.Tide - Identity.hasRole() function - invalid arguments

I have this block of actionscript code which is executed when a login is appempted. I an trying to reload a set of roles for a the user. I've added a result handler to the hasRole() method
[Observer("loginAttempted")]
public function loginAttempted():void {
identity.isLoggedIn(isLoggedInResult);
trace(identity.loggedIn+" "+identity.username);
var perms:Array = Permission.constants;
var i:int
trace("Load permissions");
for(i=0;i<perms.length;i++)
{
var p:Permission = perms[i];
var res = identity.hasRole(p.name,permissionResult);
if(res == true)
{
p.allowed = res;
}
trace(i+" "+p.name +" "+p.allowed+" "+res);
}
}
private function permissionResult(event:TideResultEvent):void {
trace("permissionResult "+event.result);
}
but i keep getting this error. Based on the graniteds docs the function should only take a single argument.
[Fault] exception, information=ArgumentError: Error #1063:
Argument count mismatch on Main/permissionResult(). Expected 1, got 2.
at TideRoleResponder/result()[C:\workspace\graniteds\as3\framework\org\granite\tide\ejb\Identity.as:201]
at org.granite.tide::Tide/result()[C:\workspace\graniteds\as3\framework\org\granite\tide\Tide.as:1831]
at org.granite.tide.rpc::ComponentResponder/result()[C:\workspace\graniteds\as3\framework\org\granite\tide\rpc\ComponentResponder.as:65]
at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:199]
at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:172]
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:199]
at org.granite.tide.rpc::TideOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\workspace\graniteds\as3\framework\org\granite\tide\rpc\TideOperation.as:73]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:263]
at mx.rpc::Responder/result()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:46]
at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
at NetConnectionMessageResponder/resultHandler()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:524]
at mx.messaging::MessageResponder/result()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:199]
We are using the ifAnyGranted function on the identity to do something similar, and our result handler has 2 arguments: the TideResultEvent, and a String containing the role. Try changing the signature of the permissionResult function to:
private function permissionResult(event:TideResultEvent, role:String):void