Example #1
0
/*	list_processes()	*/
static VALUE list_processes(VALUE obj)
{
    MYSQL* m = GetHandler(obj);
    MYSQL_RES* res = mysql_list_processes(m);
    if (res == NULL)
	mysql_raise(m);
    return mysqlres2obj(res);
}
Example #2
0
Variant f_mysql_list_processes(CVarRef link_identifier /* = null */) {
  MYSQL *conn = MySQL::GetConn(link_identifier);
  if (!conn) return false;
  MYSQL_RES *res = mysql_list_processes(conn);
  if (!res) {
    raise_warning("Unable to save MySQL query result");
    return false;
  }
  return Resource(NEWOBJ(MySQLResult)(res));
}
Example #3
0
static Variant HHVM_FUNCTION(mysql_list_processes,
                      const Variant& link_identifier /* = null */) {
  MYSQL *conn = MySQL::GetConn(link_identifier);
  if (!conn) return false;
  MYSQL_RES *res = mysql_list_processes(conn);
  if (!res) {
    raise_warning("Unable to save MySQL query result");
    return false;
  }
  return Variant(makeSmartPtr<MySQLResult>(res));
}
int main(int argc, char **argv) 
{
  MYSQL *mysql = NULL;

  mysql = mysql_init(mysql);

  if (!mysql) {
    puts("Init faild, out of memory?");
    return EXIT_FAILURE;
  }
        
  if (!mysql_real_connect(mysql,       /* MYSQL structure to use */
			  MYSQL_HOST,         /* server hostname or IP address */ 
			  MYSQL_USER,         /* mysql user */
			  MYSQL_PWD,          /* password */
			  NULL,               /* default database to use, NULL for none */
			  0,           /* port number, 0 for default */
			  NULL,        /* socket file or named pipe name */
			  CLIENT_FOUND_ROWS /* connection flags */ )) {
    puts("Connect failed\n");
  } else {                
    MYSQL_RES *result = mysql_list_processes(mysql);
                
    if (!result) {
      printf("Couldn't get process list: %s\n", mysql_error(mysql));
    } else {
      MYSQL_ROW row;
      int i;
      unsigned int num_fields = mysql_num_fields(result);
                        
      while ((row = mysql_fetch_row(result))) {
	for (i = 0; i < num_fields; i++) {
	  printf("%s, ", row[i]);
	}
	putchar('\n');
      }
                        
      mysql_free_result(result);
    }
  }
        
  mysql_close(mysql);

  return EXIT_SUCCESS;
}
Example #5
0
int main(int argc, char** argv)
{

	SqlConnection con;
	bool bok = con.ConnectToServer("192.168.1.192", 3306, "webgame", "letmego", "mysql");
	if (!bok)
	{
		return 0;
	}


	SqlBaseCmd basecmd;
	basecmd.Init(con.get_mysql_handle());
	//printf("%s", con.get_mysql_handle()->db);

	basecmd.ExecuteSqlCmd("use mysql");
	basecmd.ExecuteSqlCmd("show tables");

	SqlUseResults useresult;
	SqlStoreResults storeresult;

	useresult.Init(basecmd.GetExecuteResult());


	std::string results;
	int nrow = 0;
	char sztemp[32] = { 0 };
	useresult._FirstRow();
	while (!useresult._IsEnd())
	{
		results.clear();
		
		for (int i = 0; i < useresult.GetCol(); i ++)
		{
			memset(sztemp, 0, 32);
			useresult.GetString(useresult._GetCurRow(), i, sztemp, 32);
			results += sztemp;
			results += '\t';
		}
		printf("%s\n", results.c_str());
		useresult._MoveNextRow();
	}

	useresult.Uninit();

	//basecmd.ExecuteSqlCmd("show databases");

	printf("%%%%%%%%%%%%%%%%\n");

	storeresult.Init(mysql_list_processes(con.get_mysql_handle()));

	for (int i = 0; i < storeresult.GetRow(); i ++)
	{
		results.clear();
		for (int j = 0; j < storeresult.GetCol(); j ++)
		{
			memset(sztemp, 0, 32);
			storeresult.GetString(i, j, sztemp, 32);

			results += sztemp;
			results += '\t';
		}
		printf("%s\n", results.c_str());
	}

	storeresult.Uninit();

	con.DisConnectServer();

	
#if 0
	lihj::CSql_Helper sqlhelper;
	lihj::Sql_Paramer sqlparamer;
	sqlparamer.host = "127.0.0.1";
	sqlparamer.dbname = "testlihj";
	sqlparamer.passwd = "letmego";
	sqlparamer.port = 3306;
	sqlparamer.user = "******";
#endif

	//sqlhelper.Startup(sqlparamer);


#if 0
	printf("input sql \n");
	char szsql[256] = {0};
	while (1)
	{
		std::cin.clear();
		std::cin.ignore(256, '\n');
		std::cin.getline(szsql,512);
		if (strlen(szsql) > 0)
		{
			szsql[strlen(szsql)] = '\0';
			sqlhelper.PushBack(szsql);
		}
	}
#endif

#if 0
	lihj::CMemPool mempools;
	mempools.init();

	char* psz1 = (char*)mempools.alloc(1000);
	char* psz2 = (char*)mempools.alloc(1000);
	char* psz3 = (char*)mempools.alloc(1000);
	char* psz4 = (char*)mempools.alloc(1000);
	char* psz5 = (char*)mempools.alloc(1000);

	mempools.free(psz1);
	mempools.free(psz3);
	mempools.free(psz2);
	mempools.free(psz5);

	char* psz6 = (char*)mempools.alloc(23);
	char* psz7 = (char*)mempools.alloc(23);
	char* psz8 = (char*)mempools.alloc(23);
	char* psz9 = (char*)mempools.alloc(23); 
	char* psz10 = (char*)mempools.alloc(23);
// 	mempools.free(psz1);
#endif



	system("pause");
	return 0;
}
Example #6
0
int
main( int argc, char * argv[] )
{

  char		szSQL[ 200 ], aszFlds[ 25 ][ 25 ],  szDB[ 50 ] ;
  const char * pszT;
  int			i, j, k, l, x ;
  MYSQL		* myData ;
  MYSQL_RES	* res ;
  MYSQL_FIELD	* fd ;
  MYSQL_ROW	row ;

  //....just curious....
  printf( "sizeof( MYSQL ) == %d\n", sizeof( MYSQL ) ) ;
  if ( argc == 2 )
    {
      strcpy( szDB, argv[ 1 ] ) ;
      strcpy( szSQL, DEFALT_SQL_STMT ) ;
      if (!strcmp(szDB,"--debug"))
      {
	strcpy( szDB, "mysql" ) ;
	printf("Some mysql struct information (size and offset):\n");
	printf("net:\t%3d %3d\n",sizeof(myData->net),offsetof(MYSQL,net));
	printf("host:\t%3d %3d\n",sizeof(myData->host),offsetof(MYSQL,host));
	printf("port:\t%3d %3d\n",sizeof(myData->port),offsetof(MYSQL,port));
	printf("protocol_version:\t%3d %3d\n",sizeof(myData->protocol_version),
	       offsetof(MYSQL,protocol_version));
	printf("thread_id:\t%3d %3d\n",sizeof(myData->thread_id),
	       offsetof(MYSQL,thread_id));
	printf("affected_rows:\t%3d %3d\n",sizeof(myData->affected_rows),
	       offsetof(MYSQL,affected_rows));
	printf("packet_length:\t%3d %3d\n",sizeof(myData->packet_length),
	       offsetof(MYSQL,packet_length));
	printf("status:\t%3d %3d\n",sizeof(myData->status),
	       offsetof(MYSQL,status));
	printf("fields:\t%3d %3d\n",sizeof(myData->fields),
	       offsetof(MYSQL,fields));
	printf("field_alloc:\t%3d %3d\n",sizeof(myData->field_alloc),
	       offsetof(MYSQL,field_alloc));
	printf("free_me:\t%3d %3d\n",sizeof(myData->free_me),
	       offsetof(MYSQL,free_me));
	printf("options:\t%3d %3d\n",sizeof(myData->options),
	       offsetof(MYSQL,options));
	puts("");
      }
    }		
  else if ( argc > 2 ) {
    strcpy( szDB, argv[ 1 ] ) ;
    strcpy( szSQL, argv[ 2 ] ) ;
  }
  else {
    strcpy( szDB, "mysql" ) ;
    strcpy( szSQL, DEFALT_SQL_STMT ) ;
  }
  //....
		  
  if ( (myData = mysql_init((MYSQL*) 0)) && 
       mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT,
			   NULL, 0 ) )
    {
      if ( mysql_select_db( myData, szDB ) < 0 ) {
	printf( "Can't select the %s database !\n", szDB ) ;
	mysql_close( myData ) ;
	return 2 ;
      }
    }
  else {
    printf( "Can't connect to the mysql server on port %d !\n",
	    MYSQL_PORT ) ;
    mysql_close( myData ) ;
    return 1 ;
  }
  //....
  if ( ! mysql_query( myData, szSQL ) ) {
    res = mysql_store_result( myData ) ;
    i = (int) mysql_num_rows( res ) ; l = 1 ;
    printf( "Query:  %s\nNumber of records found:  %ld\n", szSQL, i ) ;
    //....we can get the field-specific characteristics here....
    for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
      strcpy( aszFlds[ x ], fd->name ) ;
    //....
    while ( row = mysql_fetch_row( res ) ) {
      j = mysql_num_fields( res ) ;
      printf( "Record #%ld:-\n", l++ ) ;
      for ( k = 0 ; k < j ; k++ )
	printf( "  Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
		(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
      puts( "==============================\n" ) ;
    }
    mysql_free_result( res ) ;
  }
  else printf( "Couldn't execute %s on the server !\n", szSQL ) ;
  //....
  puts( "====  Diagnostic info  ====" ) ;
  pszT = mysql_get_client_info() ;
  printf( "Client info: %s\n", pszT ) ;
  //....
  pszT = mysql_get_host_info( myData ) ;
  printf( "Host info: %s\n", pszT ) ;
  //....
  pszT = mysql_get_server_info( myData ) ;
  printf( "Server info: %s\n", pszT ) ;
  //....
  res = mysql_list_processes( myData ) ; l = 1 ;
  if (res)
    {
      for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
	strcpy( aszFlds[ x ], fd->name ) ;
      while ( row = mysql_fetch_row( res ) ) {
	j = mysql_num_fields( res ) ;
	printf( "Process #%ld:-\n", l++ ) ;
	for ( k = 0 ; k < j ; k++ )
	  printf( "  Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
		  (((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
	puts( "==============================\n" ) ;
      }
    }
  else
    {
      printf("Got error %s when retreiving processlist\n",mysql_error(myData));
    }
  //....
  res = mysql_list_tables( myData, "%" ) ; l = 1 ;
  for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
    strcpy( aszFlds[ x ], fd->name ) ;
  while ( row = mysql_fetch_row( res ) ) {
    j = mysql_num_fields( res ) ;
    printf( "Table #%ld:-\n", l++ ) ;
    for ( k = 0 ; k < j ; k++ )
      printf( "  Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
	      (((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
    puts( "==============================\n" ) ;
  }
  //....
  pszT = mysql_stat( myData ) ;
  puts( pszT ) ;
  //....
  mysql_close( myData ) ;
  return 0 ;

}
Example #7
0
static JSVAL list_processes(JSARGS args) {
	HandleScope scope;
	MYSQL *handle = (MYSQL *) args[0]->IntegerValue();
	return scope.Close(Integer::New((unsigned long)mysql_list_processes(handle)));
}
Example #8
0
BOOL ProList(const char * strParas , char * szReturn , int &nSize)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	bool bRet = false;
	CString strHost = _T("");
	CString strUserName = _T("");
	CString strPWD = _T("");
	int nPort = 3306;	//MySQL的默认端口号是3306

	MYSQL_RES * res;	//MYSQL数据库的记录集指针
	MYSQL_ROW row;		
	MYSQL	*mysql;	//接收MySQL数据的对象
	CStringList paramList;
	MakeStringListByChar(paramList, strParas);
	POSITION pos = paramList.GetHeadPosition();
	while(pos)
	{
		CString strTemp = paramList.GetNext(pos);
		if(strTemp.Find(__MACHINENAME__, 0)==0)
		{
			strHost = strTemp.Right(strTemp.GetLength() - (int)strlen(__MACHINENAME__));
		}
		else if(strTemp.Find(__PORT__, 0)==0)
		{
			nPort = atoi(strTemp.Right(strTemp.GetLength() - (int)strlen(__PORT__)));
		}
		else if(strTemp.Find(__USERACCOUNT__ , 0)==0)
		{
			strUserName = strTemp.Right(strTemp.GetLength() - (int)strlen(__USERACCOUNT__));
		}
		else if(strTemp.Find(__PASSWORD__ , 0)==0)
		{
			strPWD = strTemp.Right(strTemp.GetLength() - (int)strlen(__PASSWORD__));
		}
	}

	if(strHost.IsEmpty())
	{
		sprintf(szReturn,"error = %s",FuncGetStringFromIDS("SV_MYSQL","MYSQL_SERVER_HOST_IS_NULL"));
		return false;
	}
	if(nPort<=0)
	{
		sprintf(szReturn,"error = %s",FuncGetStringFromIDS("SV_MYSQL","MYSQL_SERVER_PORT_IS_BAD"));
		return false;
	}
	unsigned int i=0;
	CString strTMP = _T("");
	//////////////////////////////////////////////////

	int nID =0;							//MYSQL线程标识,你要kill一个语句的时候很有用
	unsigned long nCurrentID = 0;

	//////////////////////////////////////////////////



	if((mysql = mysql_init((MYSQL   *)NULL)) && mysql_real_connect(mysql,strHost, strUserName, strPWD, NULL, nPort,  NULL, 0))
	{
		res = mysql_list_processes(mysql);
		nCurrentID = mysql_thread_id(mysql);    //获取当前线程ID号。
		while(row = mysql_fetch_row(res))
		{
			
			nID = atoi(row[0]);
			if(nID==nCurrentID)
			{
				break;
			}

			sprintf(szReturn,"%d=%d$",nID,nID);
			strTMP+=szReturn;
			
		}
		sprintf(szReturn,"%s$",strTMP.GetBuffer(1));
		CString strInput ;
		strInput =szReturn;
		MakeCharByString(szReturn,nSize,strInput);

		mysql_free_result(res);		//关闭查询的结果集
		mysql_close(mysql);

		bRet = TRUE;
	}
	else
	{
		sprintf(szReturn, "error=%s(%s:%d)$", FuncGetStringFromIDS("SV_MYSQL",
            "MYSQL_CONNECT_DATABASE_FAILED"), strHost, nPort);
		fprintf(stderr, "Failed to connect to database: Error: %s\n",
          mysql_error(mysql));

        mysql_close( mysql ) ;
        return FALSE;
	}
/*
	const char * strEnd = szReturn;
	while(*strEnd)
	{
		PrintLog(strEnd);
		strEnd+=strlen(strEnd)+1;
	}
*/
	return TRUE;	
}