Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "ZombieProject.h"
- #include "MySQL_Blueprint_Nodes.h"
- #pragma comment(lib, "C:/Program Files/MySQL/MySQL Server 5.7/lib/libmysql.lib")
- #include "AllowWindowsPlatformTypes.h"
- #include <winsock2.h>
- #include <mysql.h>
- #include "HideWindowsPlatformTypes.h"
- #include <iostream>
- #include <string>
- #include <stdio.h>
- /*FString str1 = "Connection error : ";
- message.Append(str1);
- message.Append(mysql_error(connection));
- */
- void UMySQL_Blueprint_Nodes::PerformQuery(FString Host, FString Username, FString Password, FString Database, FString Query, TArray<FString>& QueryResult, FString& message, bool& completed)
- {
- try{
- //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("HELOOOOOOO"));
- MYSQL_RES *result;
- MYSQL_ROW row;
- MYSQL *connection, mysql;
- int state;
- mysql_init(&mysql);
- connection = mysql_real_connect(&mysql,TCHAR_TO_ANSI(*Host), TCHAR_TO_ANSI(*Username), TCHAR_TO_ANSI(*Password), TCHAR_TO_ANSI(*Database), 0, 0, 0 );
- if (connection == NULL) {
- //printf(mysql_error(&mysql));
- completed = false;
- message = mysql_error(&mysql);
- }
- state = mysql_query(connection,TCHAR_TO_ANSI(*Query));
- if (state != 0) {
- //printf(mysql_error(connection));
- completed = false;
- message = mysql_error(connection);
- }
- result = mysql_store_result(connection);
- //printf("Rows: %d\n", mysql_num_rows(result));
- while ((row = mysql_fetch_row(result)) != NULL) {
- //printf("id: %s, val: %s\n",
- //(row[0] ? row[0] : "NULL"),
- //(row[1] ? row[1] : "NULL"));
- for (int i = 0; i<mysql_num_rows(result); i++)
- {
- QueryResult.Add(row[i]);
- }
- message = "mysql_fetch_row completed";
- completed = true;
- }
- mysql_free_result(result);
- mysql_close(connection);
- message = "mysql_close(connection) completed";
- completed = true;
- }
- catch (char *ex) {
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString(ex));
- }
- }
Add Comment
Please, Sign In to add comment