0

I'm trying to connect to my local database on godot, and the _connect_to_dv_srvr() function does not return any errors. But once I try to create a connection instance, it returns null!

var db_general: MariaDBConnector
var _auth_type: AuthType = AuthType.NATIVE_PLAIN

func _ready() -> void:
    db_general = MariaDBConnector.new() 
    _connect_to_db_srvr(_auth_type,"dse_general", db_general) 
    var db_gn_ctx := MariaDBConnectContext.new()
    db_gn_ctx.db_name = general_ed["db_name"] as String
    db_gn_ctx.username = general_ed["db_native_user"] as String
    db_gn_ctx.password = general_ed["db_plain_text_pwd"] as String
    var ctx_db := MariaDBConnector.connection_instance(db_gn_ctx)
    if ctx_db == null:
        print("null!")

func _connect_to_db_srvr(p_auth_type:AuthType, db_name, db):
    var err:int = MariaDBConnector.ErrorCode.OK
    match p_auth_type:
        AuthType.NATIVE_PLAIN:
            err = db.connect_db(
                    general_ed["db_hostname"],
                    general_ed["db_port"],
                    db_name,
                    general_ed["db_native_user"],
                    general_ed["db_plain_text_pwd"],
                    MariaDBConnector.AUTH_TYPE_MYSQL_NATIVE,
                    false
            )
        AuthType.NATIVE_HASHED:
            err = db.connect_db(
                    general_ed["db_hostname"],
                    general_ed["db_port"],
                    db_name,
                    general_ed["db_native_user"],
                    general_ed["db_sha1_hashed_pwd"],
                    MariaDBConnector.AUTH_TYPE_MYSQL_NATIVE
            )
        AuthType.ED25519_PLAIN:
            err = db.connect_db(
                    general_ed["db_hostname"],
                    general_ed["db_port"],
                    db_name,
                    general_ed["db_ed_user"],
                    general_ed["db_plain_text_pwd"],
                    MariaDBConnector.AUTH_TYPE_ED25519,
                    false
            )
        AuthType.ED25519_HASHED:
                err = db.connect_db(
                    general_ed["db_hostname"],
                    general_ed["db_port"],
                    db_name,
                    general_ed["db_ed_user"],
                    general_ed["db_sha512_hashed_pwd"],
                    MariaDBConnector.AUTH_TYPE_ED25519
            )
    if err:
        print("db connect err:", err)

I tried to change some things like the username and password and it didn't give me anything different at all, but when I took out the password it returned a error 59 which doesn't make much sense. Sorry for the bad English.

3
  • Is "dse_general" the value of general_ed["db_name"] ? The github of the dbconnector states, that the plugin would print an error, if something went wrong with creating the context. Is there nothng in the console? Commented Jun 27 at 12:43
  • nothing. yes dse_general is the name of the db in this case. The console doesn't return anything Commented Jun 30 at 21:45
  • Did you check the debugger tab, or only the output? I get errors in the debugger, if I try to connect to a database.. Commented Jul 2 at 9:53

1 Answer 1

1

My guess so far:

Since you are using AUTH_TYPE_MYSQL_NATIVE you have to add the following properties to the context, or it will not be able to create the context with the plain password:

db_gn_ctx.auth_type = MariaDBConnectContext.AUTH_TYPE_MYSQL_NATIVE
db_gn_ctx.is_prehashed = false

The default here seems to be MariaDBConnector.AUTH_TYPE_ED25519 and prehashed true. This also explains, why the first half of your code works, since the connection was established, but your context has problems connecting.

As I wrote in the comments: The mmariadb conntector plugin does not print any error messages into the output. But if an error occured you will see it in the debug tab. Using your code without my changes lead to following errors:

E 0:00:02:424   maria.gd:24 @ _ready(): Password not proper for ED25519, must be 128 hex characters!
  <C++-Quelle>  src/mariadb_connector.cpp:1542 @ connect_db()
  <Stacktrace>  maria.gd:24 @ _ready()
E 0:00:02:425   maria.gd:24 @ _ready(): Failed to connect: error code 61
  <C++-Fehler>  Condition "err != ErrorCode::OK" is true. Returning: Ref<MariaDBConnector>()
  <C++-Quelle>  src/mariadb_connector.cpp:1616 @ connection_instance()
  <Stacktrace>  maria.gd:24 @ _ready()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.