Coder Social home page Coder Social logo

overextended / oxmysql Goto Github PK

View Code? Open in Web Editor NEW
306.0 29.0 193.0 1.08 MB

MySQL resource for FXServer.

Home Page: https://overextended.dev/oxmysql

License: GNU Lesser General Public License v3.0

JavaScript 4.45% Lua 5.10% TypeScript 67.06% HTML 0.49% CSS 0.53% Svelte 22.37%
fivem mysql

oxmysql's Introduction

oxmysql

A FiveM resource to communicate with a MySQL database using node-mysql2.

πŸ”— Links

  • πŸ’Ύ Download
    • Download the latest release directly.
  • πŸ“š Documentation
    • For installation, setup, and everything else.
  • πŸ“¦ npm
    • Use our npm package for enhanced functionality and TypeScript support.

✨ Features

  • Support for mysql-async and ghmattimysql syntax.
  • Promises / async query handling allowing for non-blocking and awaitable responses.
  • Improved performance and stability compared to other options.
  • Support for named and unnamed placeholders, improving performance and security.
  • Support for URI connection strings and semicolon separated values.
  • Improved parameter checking and error handling.

🧾 Logging

We have included a module for submitting error logs to Fivemanage, a cloud management service tailored for game servers. Additional logging options and support for other services will be available in the future.

Lua Language Server

  • Install Lua Language Server to ease development with annotations, type checking, diagnostics, and more.
  • See ox_types for our Lua type definitions.

oxmysql's People

Contributors

1a3dev avatar berkiebb avatar chaixshot avatar cu-chi-zz avatar darksaid98 avatar dunak-debug avatar github-actions[bot] avatar itschip avatar jaimeadf avatar lalashkin avatar lukewastakenn avatar niekschoemaker avatar thelindat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oxmysql's Issues

Executing multiple statements in a single query

Ox is not allowing to execute more than one query in the same request separated by ; presenting the error:

You have an error in your SQL syntax; check the manual...

CREATE TABLE ... ; ALTER TABLE... 

This is used for eg installation of new tables when starting a script that makes CreateTable with AlterTable all in the same query for multi-execution!

Separating them works normally but turns into dai calls!

Direct tests performed with mysql2 and identified that it does not support this!

oxmysql wont connect to database sending citizen error

so i updated my server did it local host first . local host works connects to database, when i upload the server via vps its crashing on alot of errors on things that i did not touch

[ script:ghmattimysql] [ghmattimysql] [SUCCESS] Database server connection established.

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-drugs/server/deliveries.lua:210)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-lapraces/server/main.lua:7)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-houses/server/main.lua:3)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-banking/server/main.lua:8)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-core/server/main.lua:21)

[ script:qb-methlab] Lab entry has been set to location: 1

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-spawn/server.lua:3)

[ svadhesive] Server license key authentication succeeded. Welcome!

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql

[ script:oxmysql] > fn (@qb-weed/server/main.lua:39)

my database password string is set up correctly i dont understand why it would'nt work its crashing lapraces and i did not touch that banking i didnt touch , what is going on ?

i get this type error in the server console using 1.7.0

Issue checklist

Please put x inside of the box that matches your issue.

  • I am using the latest release
  • I have referenced previously reported issues
  • I have referenced available documentation and cannot resolve the issue
  • I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug
this is the error i get in the server console

[ script:oxmysql] Database server connection established!
[ script:oxmysql] Uncaught TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
[ script:oxmysql] node:internal/errors(464,5): __node_internal_captureLargerStackTrace
[ script:oxmysql] node:internal/errors(371,5): NodeError
[ script:oxmysql] node:buffer(322,9): from
[ script:oxmysql] @oxmysql/oxmysql.js(1,311927): t.encode
[ script:oxmysql] @oxmysql/oxmysql.js(1,304656): toPacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,98097): start
[ script:oxmysql] @oxmysql/oxmysql.js(1,92161): execute
[ script:oxmysql] @oxmysql/oxmysql.js(1,112506): handlePacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,112628): handlePacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,107273):
[ script:oxmysql]
[ script:oxmysql] TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
[ script:oxmysql] Uncaught TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
[ script:oxmysql] node:internal/errors(464,5): __node_internal_captureLargerStackTrace
[ script:oxmysql] node:internal/errors(371,5): NodeError
[ script:oxmysql] node:buffer(322,9): from
[ script:oxmysql] @oxmysql/oxmysql.js(1,311927): t.encode
[ script:oxmysql] @oxmysql/oxmysql.js(1,304656): toPacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,98097): start
[ script:oxmysql] @oxmysql/oxmysql.js(1,92161): execute
[ script:oxmysql] @oxmysql/oxmysql.js(1,112506): handlePacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,112628): handlePacket
[ script:oxmysql] @oxmysql/oxmysql.js(1,107273):
[ script:oxmysql]
[ script:oxmysql] TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

Server details

  • FX Server artifact - 3846
  • Operating system - windows
  • Framework - qb-core framework

TIMESTAMP return table not number.

Database time is TIMESTAMP type.

local result = "SELECT time AS time FROM phone_messages LIMIT 1"
print(result[1].time)

In mysql-async will get a float value 1631181159000.0 (GCPHONE sort sms data by this number.)
In oxmysql will get table data table: 000001FE16562B60 (no value in for loop)
If set mysql_connection_string "?dateStrings=true" will get string 2021-09-09 16:52:39

Failed to execute simple SELECT

Issue checklist

Please put x inside of the box that matches your issue.

  • I am using the latest release
  • I have referenced previously reported issues
  • I have referenced available documentation and cannot resolve the issue
  • I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug
So my addon fetches all vehicles owned by non-citizens periodic with:

Citizen.CreateThread(function()
    while true do
        MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE job != @job', {job = 'citizen'}, function(data)
            VehicleTable = {}
            for k, v in pairs(data) do -- this is line 53 in sealife_society/server/main.lua
                VehicleTable[v.plate] = v
            end
        end)

        Citizen.Wait(60000)
    end
end)

I recently updated to the latest version and im now getting this error message, i normally know what to do in this case, but the query just worked fine in a older version:

[      script:oxmysql] 
[      script:oxmysql] [ERROR] sealife_society was unable to execute a query!
[      script:oxmysql]         You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'TRANSACTIONed_vehi\0012' at line 1
[      script:oxmysql]         SELECT * FROM owned_vehicles WHERE job != 'citizen'
[script:sealife_socie] SCRIPT ERROR: @sealife_society/server/main.lua:53: bad argument #1 to 'for iterator' (table expected, got nil)
[script:sealife_socie] > ref (@sealife_society/server/main.lua:53)

Code

See above

Expected behavior

A array returning containing all the data :D

Server details
FX Server: 4517
OS: Ubuntu 20 LTS
Framework: ESX ?

Dont work with some password

my root user has a password like b@66@c#22c and the URL will be
set mysql_connection_string "mysql://root:b@66@c#2
2c@localhost/lsrp?charset=utf8mb4"
and when the SQL will go run it will say
image

where like statement not working how it should

When you doing

exports.oxmysql:fetch('SELECT * FROM `players` WHERE `job` LIKE "%@idk%"', { ["@idk"] = "cardealer" }, function(result)
    print(#result) -- Expected result: 3, Result: 0
end)

It like something happens when you doing where statement like this.

No resouce for QB-Crypto

[ script:qb-crypto] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export insert in resource oxmysql

Error calling system tick function in resource oxmysql: Error: Undefined parameter fivem

local license = "none"
local discord = "none"
local xbl = "none"
local live = "none"
local fivem = "none"
for k,v in pairs(GetPlayerIdentifiers(_source)) do
  if string.sub(v, 1, string.len("steam:")) == "steam:" then
	  steamid = v
  elseif string.sub(v, 1, string.len("license:")) == "license:" then
	  license = v
  elseif string.sub(v, 1, string.len("xbl:")) == "xbl:" then
	  xbl  = v
  elseif string.sub(v, 1, string.len("discord:")) == "discord:" then
	  discord = v
  elseif string.sub(v, 1, string.len("live:")) == "live:" then
	  live = v
  elseif string.sub(v, 1, string.len("fivem:")) == "fivem:" then
	  fivem = v
  end
end

local discord_data = MySQL.Sync.fetchAll('SELECT * FROM `discord` WHERE `identifier` = @identifier AND (discord = @license OR discord = @discord OR discord = @xbl OR discord = @live OR discord = @fivem)', {
	['@identifier'] = steamid,
	['@license'] = license,
	['@discord'] = discord,
	['@xbl'] = xbl,
	['@live'] = live,
	['@fivem'] = fivem,
})

[ script:oxmysql] Error calling system tick function in resource oxmysql: Error: Undefined parameter fivem
[ script:oxmysql] stack:
[ script:oxmysql] Error: Undefined parameter fivem
[ script:oxmysql] at @oxmysql/oxmysql.js:5758:67
[ script:oxmysql] at _ (@oxmysql/oxmysql.js:5762:30)
[ script:oxmysql] at s._resolveNamedPlaceholders (@oxmysql/oxmysql.js:3373:64)
[ script:oxmysql] at s.query (@oxmysql/oxmysql.js:3378:103)
[ script:oxmysql] at @oxmysql/oxmysql.js:5188:35
[ script:oxmysql] at @oxmysql/oxmysql.js:5161:146
[ script:oxmysql] at processTicksAndRejections (internal/process/task_queues.js:75:11)
[ script:oxmysql] at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:62:3)
[ script:oxmysql] at citizen:/scripting/v8/timer.js:227:32

Ready function

Hey,

So noticed on a dev server, if the cache takes abit of time to generate, you end up with an error first time for mysql calls if you then relaunch the server it will fix it.

Would it be possible to do a ready function like async, so mysql code is not excecuted before the pool is actually connected to the sql server?

Implement a graph, showing the overall performance

People that have used ghmattimysql can probably remember that it had a feature, which shows the performance of the resource, using a graph, you could see every second how many queries were executed, how many milliseconds they took and etc, it was on the command /mysql.

Fatal error in HandleScope::HandleScope # Entering the V8 API without proper locking in place

When i start my server with oxmysql ensured and only when this script starts will I get this error then my server will just shut off I have tried everything and not found solution. I noticed another issue which has been closed that had the same title however i have tried what that said and nothing worked i have no other errors and my sql is set up properly. Hope someone can help :)

sync functions throws a nasty error

So today i decided to test oxmysql just to see how quick it is and if i wanna integrate it with alls cripts.

But found one major issue so fare, did a very very simple test.

local affectedRows = exports.oxmysql:executeSync('INSERT INTO testdb (name, data) VALUES (:name, :data)', {
    ['name'] = 'nisse',
    ['data'] = 'ged'
})

print('Updated '..affectedRows..' rows')

This resulted in a nasty error

[ script:drp_mechanic] Error loading script server/main.lua in resource drp_mechanic: citizen:/scripting/lua/scheduler.lua:1129: An error happened while calling export executeSync of resource oxmysql (attempt to yield from outside a coroutine), see above for details
[ script:drp_mechanic] stack traceback:
[ script:drp_mechanic]  [C]: in function 'error'
[ script:drp_mechanic]  citizen:/scripting/lua/scheduler.lua:1129: in function <citizen:/scripting/lua/scheduler.lua:1126>
[ script:drp_mechanic]  (...tail calls...)
[ script:drp_mechanic]  @drp_mechanic/server/main.lua:68: in main chunk
[    c-scripting-core] Failed to load script server/main.lua.
[ citizen-server-impl] Started resource drp_mechanic
cfx> [ script:drp_mechanic] SCRIPT ERROR: cannot resume non-suspended coroutine

[enhancement] Documentation improvements

The documentation could use some better/more complex examples like:
using ? or :named parameters and how to pass their information like in the insert section.
Also something going in details about { vars } vs {{ vars }} ? I think. I got caught on one of those I think

unknown error using different mysql_connection_string

when set mysql_connection_string "mysql://root:[email protected]/wcore?charset=utf8" and .execute returns
"TypeError: Cannot read properties of undefined (reading 'length')"

and when use without "?charset=utf8" the error is
"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be a type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined"

Example of my code
image

Execute crashes when calling Procedures

Using MySQL Procedures with oxmysql:execute seems to just kill my server with no error logs or trace, tested with this procedure which works perfectly with ghmattimysql:

exports.oxmysql:execute("CALL `TropixRP_CreatePlayerData` (?, ?, ?, ?, ?, ?, ?)", {ID, SteamID, Discord, FirstName, LastName})

vs

exports.ghmattimysql:execute("CALL `TropixRP_CreatePlayerData` (@ID, @SteamID, @Discord, @FirstName, @LastName)",
    {
        ["@ID"] = ID,
        ["@SteamID"] = SteamID,
        ["@Discord"] = Discord,
        ["@FirstName"] = FirstName,
        ["@LastName"] = LastName,
    })

Unable to execute named parameters using '@' in the parameter

Version 1.6.0 at same execute fucntion

MySQL.ready(function()
	MySQL.Async.execute('INSERT INTO discord(identifier, discord) VALUES(@identifier, @discord)',
	{
		['@identifier'] = "steam:11000013d8d70d5",
		['@discord'] = "xbl:2535406267274231",
	})
end)

image

Issue with not providing parameters to query

I am having an issue where if I build a full query string before passing it to oxmysql function it happens to replace some of it with NULLs as the string has :.

That's how I passed the string to the oxmysql function:

self.saveByIdSync = function(id)
  exports.oxmysql:executeSync(self.getSaveQuery(id), {})
end

But it seems to work just fine if I replace the empty array with a nil

self.saveByIdSync = function(id)
  exports.oxmysql:executeSync(self.getSaveQuery(id), nil)
end

How the build query string looks like:

[ script:extendedmode] INSERT INTO inventories SET degrade_multiplier = '1.0',
[ script:extendedmode] id = 'police_locker_Char2:e76088cbb700507476828a532085599d1395d44d',
[ script:extendedmode] type = 'container',
[ script:extendedmode] data = '{"items":[]}' ON DUPLICATE KEY UPDATE degrade_multiplier = '1.0',
[ script:extendedmode] id = 'police_locker_Char2:e76088cbb700507476828a532085599d1395d44d',
[ script:extendedmode] type = 'container',
[ script:extendedmode] data = '{"items":[]}'

Error thrown to console (you can see that the : where replaced with NULLs):

[      script:oxmysql] [ERROR] extendedmode was unable to execute a query!
[      script:oxmysql]         Duplicate entry 'police_locker_Char2NULL' for key 'PRIMARY'
[      script:oxmysql]         INSERT INTO inventories SET degrade_multiplier = '1.0',
[      script:oxmysql] id = 'police_locker_Char2:e76088cbb700507476828a532085599d1395d44d',
[      script:oxmysql] type = 'container',
[      script:oxmysql] data = '{"items":[]}' ON DUPLICATE KEY UPDATE degrade_multiplier = '1.0',
[      script:oxmysql] id = 'police_locker_Char2NULL',
[      script:oxmysql] type = 'container',
[      script:oxmysql] data = '{"items":[]}'

Error: read ECONNRESET

Issue checklist

Please put x inside of the box that matches your issue.

  • [ x ] I am using the latest release
  • I have referenced previously reported issues
  • I have referenced available documentation and cannot resolve the issue
  • [ x ] I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug

[ERROR] test was unable to execute a query!
[      script:oxmysql]         read ECONNRESET
[      script:oxmysql]         UPDATE users SET rp_xp = ?, rp_rank = ? WHERE identifier = ? [689500,7,"char1:steam:00000"]
[      script:oxmysql] Trace: Error: read ECONNRESET
[      script:oxmysql]     at PromisePool.query (@oxmysql/oxmysql.js:17259:38)
[      script:oxmysql]     at execute (@oxmysql/oxmysql.js:20125:58)
[      script:oxmysql]     at Object.callback (@oxmysql/oxmysql.js:20341:13)
[      script:oxmysql]     at citizen:/scripting/v8/main.js:156:41
[      script:oxmysql]     at Number.__cfx_wrap_588 (citizen:/scripting/v8/main.js:24:12)
[      script:oxmysql]     at citizen:/scripting/v8/main.js:30:16
[      script:oxmysql]     at citizen:/scripting/v8/main.js:155:11
[      script:oxmysql]     at Console.trace (citizen:/scripting/v8/console.js:297:19)
[      script:oxmysql]     at execute (@oxmysql/oxmysql.js:20140:34)
[      script:oxmysql]     at processTicksAndRejections (node:internal/process/task_queues:96:5)

Code

exports.oxmysql:update('UPDATE users SET rp_xp = ?, rp_rank = ? WHERE identifier = ?', {
            goalXP,
            goalRank,
            xPlayer.identifier
        }, function(result)

        end)

Additional context
well , sometimes this and only this query get this error ! but mostly it will executed without any errors , so based on some searches i guess i have to increase the wait timout for mysql ? but why this happens for only this query ? on a table that contains like 5 row max ! ( test server )

example log of same query executing without an error

[      script:oxmysql] [DEBUG] test took 0ms to execute a query!
[      script:oxmysql]         UPDATE users SET rp_xp = ?, rp_rank = ? WHERE identifier = ? [966000,10,"char1:steam:00000"]

Server details

  • FX Server artifact = 4920
  • Operating system = win 10
  • Framework = extended

Fatal Error in HandleScope::HandleScope

i saw the post in the FiveM forum and I decided to try it, I downloaded the build, I started it, I set the server.cfg and after I tried to do a simple select and the server crashed with this error, I don't know if I did something wrong but I couldn't test it
immagine_2021-09-10_222829

My connection string: mysql://root@localhost/utility?charset=utf8mb4

CONCAT Doesnt work

Hello, i found problem with CONCAT in oxmysql, here is example:

local resultDepartment = exports.oxmysql:fetch('SELECT CONCAT(\'(\',job.label,\' - \', grade.label,\')\') as departmentGrade FROM jobsjob joinjob_grades grade on job.name = grade.job_name WHERE job.name=@job and grade.grade = @job_grade', { ['job'] = jobName, ['job_grade'] = jobGrade } );

and error:

[ script:oxmysql] Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?.label,' - ', grade.label,')') as departmentGrade FROM jobs job join job_gra' at line 1 SELECT CONCAT('(',job.label,' - ', grade.label,')') as departmentGrade FROM jobs job join job_grades grade on job.name = grade.job_name WHERE job.name=:job and grade.grade = :job_grade {
[ script:oxmysql] "job_grade": 3,
[ script:oxmysql] "job": "sheriff"`

Question with double query

How can I make the query below:

INSERT INTO vrp_users (whitelisted, banned, garage) VALUES (false, false, 3); SELECT LAST_INSERT_ID() AS id

Because if I break it in two moments it can't get the last id, because it's a new connection.

How to define the connection Port?

Hello,

I have my localhost database in the port 3308 but i tried to define it in the config but when I start the server the oxmysql cannot connect with the database.
I think this happens because the script use the default port 3306.

Screenshot_1

I tried the following connection strings:
set mysql_connection_string "mysql://user:password@localhost:3308/rs-test?charset=utf8mb4"

set mysql_connection_string "mysql://user:[email protected]:3308/rs-test?charset=utf8mb4"

set mysql_connection_string "mysql://localhost:3308/rs-framework?user=tets&password=test123"

How I can modify the port?

Production Problem with thread_monitor Resource temporarily unavailable in pthread_create

Issue checklist

  • I am using the latest release
  • I have referenced previously reported issues
  • I have referenced available documentation and cannot resolve the issue
  • I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug

We moved oxmysql on our production server (FXServer 4960) and the server instantly crash if a player connects with the following error:

thread_monitor Resource temporarily unavailable in pthread_create
thread_monitor Resource temporarily unavailable in pthread_create
thread_monitor Resource temporarily unavailable in pthread_create
thread_monitor Resource temporarily unavailable in pthread_create
thread_monitor Resource temporarily unavailable in pthread_create
thread_monitor Resource temporarily unavailable in pthread_create
> quit "Server Restart (Crash erkannt)."

As far as i can see, the MySQL stuff works just fine, all addons can fetch their data and stuff, but as soon as a user connects, the server crashes.

We used mysql-async with a explicit utf8mb4 charset just to let you know. But i was not able to set this parameter with oxmysql as the connection string did not allow the ?... paremeter stuff like mysql-async did.

oxmysql is actually running on our test server which is FXServer 4879

Code

None

Expected behavior

No crash?

Server details

  • FXServer 4960
  • Ubuntu 20.04 LTS up-to-date
  • ESX

No Such Export

  • [x ] I am using the latest release
  • [x ] I have referenced previously reported issues
  • [x ] I have referenced available documentation and cannot resolve the issue
  • [x ] I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug
Added oxmysql whilst updated my server updated all other scripts alongside this one still proceed to have the error. I have gone through the documentation still no luck.

Console
[ cmd] Argument count mismatch (passed 1, wanted 2)
[ svadhesive] Authenticating server license key...
cfx> [ script:qb-moneysafe] SCRIPT ERROR: @qb-moneysafe/server/main.lua:7: attempt to index a nil value (global 'QBCore')
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-houses/server/main.lua:11)
[ script:qb-companies] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export execute in resource ghmattimysql
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-banking/server/main.lua:8)
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export execute in resource oxmysql
[ script:oxmysql] > fn (@qb-weed/server/main.lua:39)
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-lapraces/server/main.lua:7)
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-core/server/main.lua:18)
[ script:qb-methlab] Lab entry has been set to location: 1
[ svadhesive] Server license key authentication succeeded. Welcome!
[ citizen-server-impl] server thread hitch warning: timer interval of 752 milliseconds
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-drugs/server/deliveries.lua:210)

Unable to execute a query!

When i have more than 2 parameter script is unable to execute a query.
When i have 2 any of these paremeters it's work for example 'identifier', 'owner', or 'firstowner', 'co_owner1',
image
image

Error loading script oxmysql.js

  • I am using the latest release
  • I have referenced available documentation and cannot resolve the issue
  • I'm certain this is an issue with oxymysql, and not with my resource

Describe the bug
Error loading script oxmysql.js

Screenshots
image

Server details

  • FX Server artifact: latest
  • Operating system: Debian 10
  • Framework Qbus

V1.2.0 specific problem

It's not getting a specific column's value on the newest release
Error:Naamloos
Query:

exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (@citizenid, @cid, @license, @name, @money, @charinfo, @job, @gang, @position, @metadata)', {
  ['@citizenid'] = PlayerData.citizenid,
  ['@cid'] = tonumber(PlayerData.cid),
  ['@license'] = PlayerData.license,
  ['@name'] = PlayerData.name,
  ['@money'] = json.encode(PlayerData.money),
  ['@charinfo'] = json.encode(PlayerData.charinfo),
  ['@job'] = json.encode(PlayerData.job),
  ['@gang'] = json.encode(PlayerData.gang),
  ['@position'] = json.encode(PlayerData.position),
  ['@metadata'] = json.encode(PlayerData.metadata)
})

Converting to oxmysql

It looks like i am not getting anything from result. Am i using it wrong? How would i have to use it

[script:oxmysql] Error: Cannot convert undefined or null to object
[script:esx_addonaccount] nil
[script:esx_addonaccount] SCRIPT ERROR: @esx_addonaccount/server/main.lua:9: attempt to index a nil value (local 'result')
Citizen.CreateThread(function()
	local result = exports.oxmysql:fetch('SELECT * FROM addon_account')
        print(result)
	print(result[1])

	for i=1, #result, 1 do
		local name   = result[i].name
		local label  = result[i].label
		local shared = result[i].shared

		local result2 = exports.oxmysql:fetch('SELECT * FROM addon_account_data WHERE account_name = @account_name', {
			['@account_name'] = name
		})

		if shared == 0 then
			table.insert(AccountsIndex, name)
			Accounts[name] = {}

			for j=1, #result2, 1 do
				local addonAccount = CreateAddonAccount(name, result2[j].owner, result2[j].money)
				table.insert(Accounts[name], addonAccount)
			end
		else
			local money = nil

			if #result2 == 0 then
				exports.oxmysql:execute('INSERT INTO addon_account_data (account_name, money, owner) VALUES (@account_name, @money, NULL)', {
					['@account_name'] = name,
					['@money']        = 0
				})

				money = 0
			else
				money = result2[1].money
			end

			local addonAccount   = CreateAddonAccount(name, nil, money)
			SharedAccounts[name] = addonAccount
		end
	end
end)

TypeError cannot read property `99` of null

[ script:oxmysql] Error calling system tick function in resource oxmysql: TypeError: Cannot read property '99' of null
[ script:oxmysql] stack:
[ script:oxmysql] TypeError: Cannot read property '99' of null
[ script:oxmysql] at @oxmysql/oxmysql.js:1:331172
[ script:oxmysql] at i (@oxmysql/oxmysql.js:1:331208)
[ script:oxmysql] at s._resolveNamedPlaceholders (@oxmysql/oxmysql.js:1:113567)
[ script:oxmysql] at s.query (@oxmysql/oxmysql.js:1:113696)
[ script:oxmysql] at @oxmysql/oxmysql.js:1:317597
[ script:oxmysql] at @oxmysql/oxmysql.js:1:316120
[ script:oxmysql] at processTicksAndRejections (internal/process/task_queues.js:75:11)
[ script:oxmysql] at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:62:3)
[ script:oxmysql] at citizen:/scripting/v8/timer.js:227:32

Coudln't select by order

version '1.4.0'

        local query = exports.oxmysql:fetchSync("SELECT id, name, reward FROM gas_station_jobs WHERE gas_station_id = @gas_station_id AND progress = 0 ORDER BY id ASC", {
            ["@gas_station_id"] = gsID
        })

error

[      script:oxmysql] Error calling system tick function in resource oxmysql: Error: Undefined parameter name
[      script:oxmysql] stack:
[      script:oxmysql] Error: Undefined parameter name
[      script:oxmysql]     at toArrayParams (webpack-internal:///./node_modules/named-placeholders/index.js:106:49)
[      script:oxmysql]     at compile (webpack-internal:///./node_modules/named-placeholders/index.js:153:12)
[      script:oxmysql]     at PoolConnection._resolveNamedPlaceholders (webpack-internal:///./node_modules/mysql2/lib/connection.js:530:17)
[      script:oxmysql]     at PoolConnection.query (webpack-internal:///./node_modules/mysql2/lib/connection.js:543:10)
[      script:oxmysql]     at eval (webpack-internal:///./node_modules/mysql2/lib/pool.js:149:14)
[      script:oxmysql]     at eval (webpack-internal:///./node_modules/mysql2/lib/pool.js:45:37)
[      script:oxmysql]     at processTicksAndRejections (internal/process/task_queues.js:75:11)
[      script:oxmysql]     at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:62:3)
[      script:oxmysql]     at citizen:/scripting/v8/timer.js:227:32

Connection string does not support special characters

I created a server with the txBuilder and after awhile trying to debug why the module oxmysql did not have a fetch operation i discovered (while trying to reload the module) that there was a parsing issue with a url parameter
looking back at the password i supplied to mysql i saw where the issue was .
can we get the error message to be appropriate while loading to have the user know this is the source of the issue

   }
            const tokens = connectionStringParser.exec(uri);
            if (Array.isArray(tokens)) {
                connectionStringObject.scheme = tokens[1];
                if (this.scheme && this.scheme !== connectionStringObject.scheme) {
                    throw new Error(`URI must start with '${this.scheme}://'`);
                }
                connectionStringObject.username = tokens[2] ? decodeURIComponent(tokens[2]) : tokens[2];
                connectionStringObject.password = tokens[3] ? decodeURIComponent(tokens[3]) : tokens[3]; // this line of code
                connectionStringObject.hosts = this._parseAddress(tokens[4]);
                connectionStringObject.endpoint = tokens[5] ? decodeURIComponent(tokens[5]) : tokens[5];
                connectionStringObject.options = tokens[6] ? this._parseOptions(tokens[6]) : tokens[6];
            }

Undefined parameters when sending nil values from Lua

when a variable in LIA has value of nil the sql query throws an error

In this example garage is nil It comes from the DB select as NULL in the table which is the default value
But when it is inserted back it seems to ignore it and causes the undefined object.

[ script:oxmysql] [ERROR] qb-garages was unable to execute a query!
[ script:oxmysql] Undefined object parameter #2
[ script:oxmysql] UPDATE player_vehicles SET state = ?, garage = ?, depotprice = ? WHERE plate = ? {"1":0,"3":0,"4":"3TL036RH"}

Is there a way to have it recognize nil value and insert them as NULL?

Cannot read properties of null (reading 'length')

On version v1.6.2 I have this error (error doesn't happen on v1.6.1)

[      script:oxmysql] [ERROR] mx-multicharacter was unable to execute a query!
[      script:oxmysql]         Cannot read properties of null (reading 'length')
[      script:oxmysql]         SELECT charid FROM user_lastcharacter WHERE identifier = 'steam:11000011377f8e4' null
[      script:oxmysql] [ERROR] mx-multicharacter was unable to execute a query!
[      script:oxmysql]         Cannot read properties of null (reading 'length')
[      script:oxmysql]         INSERT INTO user_lastcharacter (identifier, charid) VALUES('steam:11000011377f8e4', 1) null```

oxmysl error in qbcore framework

Hey guys, Just installed a fresh copy of the QBCore Framewor and I cannot connect .. checking for a ban takes way too long and then i get code CURL 18 error .
I get the error in console
[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
could you guys point me in the right direction on how to fix this issue ?

I thought it might be an SQL credential issue but the dbname, user and password all look fine to me

this is also happening on boot up of server.
`[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-banking/server/main.lua:8)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-weed/server/main.lua:39)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-spawn/server.lua:3)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-lapraces/server/main.lua:7)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-core/server/events.lua:236)

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-houses/server/main.lua:3)

[ citizen-server-impl] server thread hitch warning: timer interval of 523 milliseconds

[ script:oxmysql] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:1155: No such export fetch in resource oxmysql
[ script:oxmysql] > fn (@qb-drugs/server/deliveries.lua:210)

Was unable to execute a query

Hey, guys!
I'm having trouble building a query that automatically creates the database, I did a test with ghmattimysql (node ​​version) and managed to create the database successfully.

Issue checklist

Please put x inside of the box that matches your issue.

  • I am using the latest release
  • I have referenced previously reported issues
  • I have referenced available documentation and cannot resolve the issue
  • I'm certain this is an issue with oxymysql, and not with my resource

Screenshots
errorPrint

Code

local connectionString = GetConvar('mysql_connection_string', '')

if connectionString:find('mysql://') then

      local databaseName = connectionString:match('[^/][%w]*[?$]'):sub(0, -2)

      exports['executeSync']:execute(('CREATE DATABASE IF NOT EXISTS %s'):format(databaseName))

end

Expected behavior
Create database

Server details

  • FX Server artifact: 4821
  • Operating system: Windows 11
  • Framework: Custom

Javascript heap out of memory

Hello,

Three days ago, we've switched to oxmysql from mysql-async. It's all been running great, except for one issue. At peak times, we often get the following error:

[ c-scripting-v8node] Error: V8 error at Reached heap limit: Allocation failed - JavaScript heap out of memory

This error appears to come out of nowhere. After this error, the fxserver just hard-resets and boots up again. We are running the esx legacy framework, and we're seeing somewhere around 250 players at peak time. OxMySQL is the only resource running v8. I'm not much of a Javascript developer myself, so I turned to your discord for help, and they also thought this issue could be caused by oxmysql, but could not help me with the solution. They did advise me to make an issue on your git, so here I am.

If you need any more information I will respond asap! <3

Specific SELECT is not working!

If you do an execute or a fetch using general selector (*) it works normally as follows:
exports.oxmysql:execute("SELECT * FROM vrp_user_moneys WHERE user_id = :user_id",{user_id = 1},function(result) print(result) end)

However, if you execute an execute specifying a selector, it returns an error:
exports.oxmysql:execute("SELECT wallet,bank FROM vrp_user_moneys WHERE user_id = :user_id",{user_id = 1},function(result) print(result) end)

Error: Error: Unknow column 'walletNULL' in 'field list' SELECT wallet,bank FROM vrp_user_moneys WHERE user_id = :user_id

If in Fetch:

Error: Error: You have an error in your SQL syntax; check the manuel that corresponds to your MariaDB server version for the right syntax to use near ': FROM vrp_user_moneys WHERE user_id = ?

Issue with DATEDIFF

Hi guys, I have a problem with the DATEDIFF, with mysql-async it worked correctly, is it possible to have more information?

I can't run more than one query in an .execute?

Example:
in oxmysql
"INSERT INTO users(whitelisted, banned) VALUES(false, false); SELECT LAST_INSERT_ID() AS id;"
or multiple "CREATE TABLE IF NOT EXISTS" in the same query string
It just doesn't run, but on others like mysql-async and ghmattimysql the query runs without problems/errors

Unable to execute multiple statements in a single query

Version: 1.6.0c and 1.5.1

I'm using the lib provided, but requests using " ; " when creating a table, selects and inserts are not working as they should.

Below is some evidence.

image

Create Table:

MySQL.Sync.execute(
            [[CREATE TABLE IF NOT EXISTS `gas_station_business`( `gas_station_id` VARCHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci', `user_id` VARCHAR(50) NOT NULL, `stock` INT(10) UNSIGNED NOT NULL DEFAULT '0', `price` INT(10) UNSIGNED NOT NULL DEFAULT '0', `stock_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `truck_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `relationship_upgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', `money` INT(10) UNSIGNED NOT NULL DEFAULT '0', `total_money_earned` INT(10) UNSIGNED NOT NULL DEFAULT '0', `total_money_spent` INT(10) UNSIGNED NOT NULL DEFAULT '0', `gas_bought` INT(10) UNSIGNED NOT NULL DEFAULT '0', `gas_sold` INT(10) UNSIGNED NOT NULL DEFAULT '0', `distance_traveled` DOUBLE UNSIGNED NOT NULL DEFAULT '0', `total_visits` INT(10) UNSIGNED NOT NULL DEFAULT '0', `customers` INT(10) UNSIGNED NOT NULL DEFAULT '0', `timer` INT(10) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`gas_station_id`) USING BTREE) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ; CREATE TABLE IF NOT EXISTS `gas_station_balance` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `gas_station_id` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci', `income` BIT(1) NOT NULL, `title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_general_ci', `amount` INT(10) UNSIGNED NOT NULL, `date` INT(10) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ; CREATE TABLE IF NOT EXISTS `gas_station_jobs` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `gas_station_id` VARCHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci', `name` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci', `reward` INT(10) UNSIGNED NOT NULL DEFAULT '0', `amount` INT(11) NOT NULL DEFAULT '0', `progress` BIT(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`) USING BTREE ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB ;]]
        )
                local o =
                    "INSERT INTO `gas_station_business` (user_id,gas_station_id,stock,timer) VALUES (@user_id,@gas_station_id,@stock,@timer);"
                MySQL.Sync.execute(
                    o,
                    {["@gas_station_id"] = r, ["@user_id"] = s, ["@stock"] = 0, ["@timer"] = os.time()}
                )

Both in insert when select using @ it recognizes as null.

Debug enhancement

add debug in file console or both config and debug level
like these

set mysql_log_level 8
set mysql_debug "File"
set mysql_log_file_format "debug-mysql.log"

image
image
image

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.