mariadb set charset: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
 
Line 2: Line 2:
{{Notice|This function is provided by the official [[MariaDB]] plugin.}}
{{Notice|This function is provided by the official [[MariaDB]] plugin.}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Sets the sqlserver charset to be used.
 
List of character sets: https://mariadb.com/kb/en/mysql_set_character_set/}}


{{FuncSyntax|mariadb_set_charset(handle_id, charset_str)}}
{{FuncSyntax|mariadb_set_charset(handle_id, charset_str)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|handle_id|__EDIT_ME__}}
{{FuncParam|handle_id|The connection handle.}}
{{FuncParam|charset_str|__EDIT_ME__}}
{{FuncParam|charset_str|The charset}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success.}}


== Example ==
== Example ==
Example taken from: https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/master/horizon/server/database.lua
<syntaxhighlight lang="Lua">
<syntaxhighlight lang="Lua">
-- code
sql = false
 
local SQL_HOST = "localhost"
local SQL_PORT = 3306
local SQL_USER = "user"
local SQL_PASS = "pass"
local SQL_DATA = "dbname"
local SQL_CHAR = "utf8mb4"
local SQL_LOGL = "debug"
 
-- Setup a MariaDB connection when the package/server starts
local function OnPackageStart()
mariadb_log(SQL_LOGL)
 
sql = mariadb_connect(SQL_HOST .. ':' .. SQL_PORT, SQL_USER, SQL_PASS, SQL_DATA)
 
if (sql ~= false) then
print("MariaDB: Connected to " .. SQL_HOST)
mariadb_set_charset(sql, SQL_CHAR)
else
print("MariaDB: Connection failed to " .. SQL_HOST .. ", see mariadb_log file")
 
-- Immediately stop the server if we cannot connect
ServerExit()
end
 
CallEvent("database:connected")
end
</syntaxhighlight>
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
{{MariaDBFunctions}}
{{MariaDBFunctions}}

Latest revision as of 09:12, 2 September 2020

mariadb set charset

Type: Function
Context: Server
Introduced: v1.0

NOTICE

This function is provided by the official MariaDB plugin.

Description

Sets the sqlserver charset to be used.

List of character sets: https://mariadb.com/kb/en/mysql_set_character_set/

Syntax

mariadb_set_charset(handle_id, charset_str)

Parameters

  • handle_id
    The connection handle.
  • charset_str
    The charset

Return Value

  • Returns true on success.

Example

Example taken from: https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/master/horizon/server/database.lua

sql = false

local SQL_HOST = "localhost"
local SQL_PORT = 3306
local SQL_USER = "user"
local SQL_PASS = "pass"
local SQL_DATA = "dbname"
local SQL_CHAR = "utf8mb4"
local SQL_LOGL = "debug"

-- Setup a MariaDB connection when the package/server starts
local function OnPackageStart()
	mariadb_log(SQL_LOGL)

	sql = mariadb_connect(SQL_HOST .. ':' .. SQL_PORT, SQL_USER, SQL_PASS, SQL_DATA)

	if (sql ~= false) then
		print("MariaDB: Connected to " .. SQL_HOST)
		mariadb_set_charset(sql, SQL_CHAR)
	else
		print("MariaDB: Connection failed to " .. SQL_HOST .. ", see mariadb_log file")

		-- Immediately stop the server if we cannot connect
		ServerExit()
	end

	CallEvent("database:connected")
end

See also