Code Monkey home page Code Monkey logo

ue4_connector_mysql_plugin's Introduction

UE4 MySQL插件使用

1. 插件获取

MySQL Plugin 提取码:17um

2. 插件安装

  1. 新建UE4项目,类型随意
  2. 项目根目录中新建文件夹Plugins
  3. FH_MySQL复制到Plugins
  4. 重新打开UE4项目

3. 插件API

3.1 连接数据库

  • 返回一个MySQL Connector

    /*
     * Connection == MySQL Object
     * @return *UFH_ConnectionObject == MySQL Connector
    */
    UFUNCTION(BlueprintCallable, Category="MySQL|Utils")
    static UFH_ConnectionObject *ConnectToMySQL(FString Host, FString UserName, FString PassWord, FString DBName,
                                                int32 Port, FString &ConnectMessage);

3.2 获得连接状态

  • 返回bool,正在连接返回true

    /*
     * ConnectionObject == MySQL Object
     * @return bool == ConnectionState
    */
    UFUNCTION(BlueprintCallable, Category="MySQL|Utils")
    static bool GetConnectionState(UFH_ConnectionObject *ConnectionObject);

3.3 关闭数据库连接

  • 肯定会关掉,默认返回true

    /*
     * ConnectionObject == MySQL Object
     * @return bool == ConnectionState
    */
    UFUNCTION(BlueprintCallable, Category="MySQL|Utils")
    static bool CloseConnection(UFH_ConnectionObject *ConnectionObject);

3.4 增-删-改处理

  • 实现增删改的处理,具体执行程序依据传入格式化SqlQuery

  • InsertDeleteUpdate

    /*
     * ConnectionObject == MySQL Object
     * @return bool == Insert, Update, Delete Data Is Succeed Or Failed
    */
    UFUNCTION(BlueprintCallable, Category="MySQL|Utils")
    static bool ActionOnTableData(UFH_ConnectionObject *ConnectionObject, FString SqlQuery);
3.4.1 Insert Format SqlQuery
  • 通用的 INSERT INTO TableName VALUES(InsertValues);格式化插入语句

    /*
     * TableName = DataBase TableName
     * InsertValues = MySQL Insert Values to Table
     * @return FString = MySQL Insert Query -> Insert
    */
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString InsertFormatSqlQuery(FString TableName, FString InsertValues);
3.4.2 Update Format SqlQuery
  • 更新所有字段的值UPDATE TableName SET RowName = UpdateValue;格式化更新语句

    /*
     * TableName = DataBase TableName
     * RowName = Need Update Row
     * @return FString = MySQL Update Query -> Update
    */	
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString UpdateAllFormatSqlQuery(FString TableName, FString RowName, FString UpdateValue);
  • 依据条件更新字段值UPDATE TableName SET UpdateRowName = UpdateValue WHERE WhereName = WhereValue;格式化更新语句

    /*
     * TableName = DataBase TableName
     * RowName = Need Update Row
     * WhereName = Update Where
     * WhereSymbol = Operator Or Symbol
     * WhereValue = Condition Name
     * UpdateValue = Need Update Date Value
     * @return FString = MySQL Update Query -> Update
    */	
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString UpdateByWhereFormatSqlQuery(FString TableName, FString RowName, FString WhereName, 
                                               FString WhereSymbol, FString WhereValue, FString UpdateValue);
3.4.3 Delete Format SqlQuery
  • 删除整个表DELETE FROM TableName;格式化删除语句

    /*
     * TableName = DataBase TableName
     * @return FString = MySQL Delete Query -> Delete
    */
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString DeleteAllFormatSqlQuery(FString TableName);
  • 依据条件删除整行数据DELETE FROM TableName WHERE WhereName=‘WhereValue’;格式化删除语句

    /*
     * TableName = DataBase TableName
     * WhereName = Update Where
     * WhereSymbol = Operator Or Symbol
     * WhereValue = Condition Name
     * @return FString = MySQL Delete Query -> Delete
    */
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString DeleteByWhereFormatSqlQuery(FString TableName, FString WhereName, FString WhereSymbol, 
                                               FString WhereValue);

3.5 查询语句处理

  • 实现基本常用的查询语句:

    1. SELECT * FROM TableName;
    2. SELECT Columns1, Columns2, Country FROM TableName;
    3. 获得指定行的整行数据
  • 处理查询语句的通用,具体执行程序依据传入格式化SqlQuery

  • 函数公开生成并返回struct类型:

    • ResultRows整个表的数据
    • ResultRow整行的数据
    • RowValue整行内字段名的数据
    /*
     * ConnectionObject == MySQL Object
     * @return bool == Select Data Is Succeed Or Failed
    */	
    UFUNCTION(BlueprintCallable, Category="MySQL|Utils")
    static bool SelectOnTableData(UFH_ConnectionObject *ConnectionObject, FString SqlQuery, 
                                  FQueryResultRows &ResultRows);
3.5.1 Select All Format SqlQuery
  • 查询整个表的数据SELECT * FROM TableName;格式化查询语句

    /*
     * TableName = DataBase TableName
     * @return FString = MySQL Select Query -> Select
    */
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString SelectAllFormatSqlQuery(FString TableName);
3.5.2 Select Columns By Conditions
  • 依据条件查询表内数据SELECT Columns1, Columns2, Country FROM TableName;格式化查询语句

    /*
     * TableName = DataBase TableName
     * @return FString = MySQL Select Query -> Select
    */	
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FString SelectByColumnsFormatSqlQuery(FString TableName, FString Columns);
3.5.3 Select Get RowValues By Index
  • 指定表面和表内的行号,查询数据

    /*
     * TableName = DataBase TableName
     * @return TArray<FString> = Get All Rows -> In All Columns Values
    */		
    UFUNCTION(BlueprintPure, Category="MySQL|Utils")
    static FQueryResultRow GetRowByIndex(const FQueryResultRows &ResultRows, int32 RowIndex);

ue4_connector_mysql_plugin's People

Contributors

fhangh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.