Guest User

Untitled

a guest
Sep 18th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "ZombieProject.h"
  5. #include "MySQL_Blueprint_Nodes.h"
  6.  
  7. #pragma comment(lib, "C:/Program Files/MySQL/MySQL Server 5.7/lib/libmysql.lib")
  8.  
  9. #include "AllowWindowsPlatformTypes.h"
  10. #include <winsock2.h>
  11. #include <mysql.h>
  12. #include "HideWindowsPlatformTypes.h"
  13. #include <iostream>
  14. #include <string>
  15. #include <stdio.h>
  16.  
  17. /*FString str1 = "Connection error : ";
  18.            
  19.             message.Append(str1);
  20.             message.Append(mysql_error(connection));
  21.             */
  22.  
  23. void UMySQL_Blueprint_Nodes::PerformQuery(FString Host, FString Username, FString Password, FString Database, FString Query, TArray<FString>& QueryResult, FString& message, bool& completed)
  24. {
  25.     try{
  26.         //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("HELOOOOOOO"));
  27.        
  28.     MYSQL_RES *result;
  29.     MYSQL_ROW row;
  30.     MYSQL *connection, mysql;
  31.     int state;
  32.    
  33.  
  34.     mysql_init(&mysql);
  35.     connection = mysql_real_connect(&mysql,TCHAR_TO_ANSI(*Host), TCHAR_TO_ANSI(*Username), TCHAR_TO_ANSI(*Password), TCHAR_TO_ANSI(*Database), 0, 0, 0 );
  36.  
  37.  
  38.     if (connection == NULL) {
  39.  
  40.  
  41.         //printf(mysql_error(&mysql));
  42.  
  43.         completed = false;
  44.         message = mysql_error(&mysql);
  45.     }
  46.  
  47.     state = mysql_query(connection,TCHAR_TO_ANSI(*Query));
  48.     if (state != 0) {
  49.         //printf(mysql_error(connection));
  50.         completed = false;
  51.         message = mysql_error(connection);
  52.     }
  53.  
  54.  
  55.     result = mysql_store_result(connection);
  56.  
  57.     //printf("Rows: %d\n", mysql_num_rows(result));
  58.  
  59.    
  60.     while ((row = mysql_fetch_row(result)) != NULL) {
  61.         //printf("id: %s, val: %s\n",
  62.         //(row[0] ? row[0] : "NULL"),
  63.         //(row[1] ? row[1] : "NULL"));
  64.         for (int i = 0; i<mysql_num_rows(result); i++)
  65.         {
  66.             QueryResult.Add(row[i]);
  67.         }
  68.  
  69.        
  70.         message = "mysql_fetch_row completed";
  71.         completed = true;
  72.     }
  73.    
  74.  
  75.     mysql_free_result(result);
  76.  
  77.     mysql_close(connection);
  78.  
  79.     message = "mysql_close(connection) completed";
  80.     completed = true;
  81.    
  82.     }
  83.     catch (char *ex) {
  84.         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString(ex));
  85.     }
  86. }
Add Comment
Please, Sign In to add comment