Commit Graph
49 Commits
Author SHA1 Message Date
Linden 46a7dabc1e fix(db): incorrect error handling when no callback is defined
Partly reverts some changes made for the experimental
transaction export.
2024-03-05 00:47:46 +11:00
Linden 123a003332 refactor(db/startTransaction): use internal query functions
Some changes to function signature and callback.
Make null-returns commit changes rather than rollback.
2024-02-09 18:06:44 +11:00
Linden e31d84019e refactor(logger): non-debug query profiling
Use less precise query profiling (script based, rather than sql
server based). Re-enables slow query warning, and reduces
overhead when ui is enabled.
2023-12-27 23:52:47 +11:00
Linden d0683b7f30 refactor(logger): handle error event in error logger 2023-12-27 13:44:05 +11:00
Linden 0398abc501 refactor(database): move pool and connection variables
Mostly reorganising module.
Added getPoolConnection helper.
2023-09-15 14:36:31 +10:00
Linden a065c1c545 fix(db/rawExecute): don't unpack responses for rawExecute
Oversight when implementing the rawExecute export. Technically breaking..
Return ResultSetHeader rather than just a number for affectedRows or insertId.
2023-09-06 13:29:04 +10:00
Linden 86aaf157fa fix: rename printError function
This apparently conflicts with and overrides a global used in cfx's JS runtime.
2023-09-06 12:31:22 +10:00
Linden 924fd6a3cf refactor: improve error handling 2023-07-28 17:21:13 +10:00
Linden f3e9aa52d9 refactor(database): use setCallback 2023-07-28 06:09:35 +10:00
Linden e07947d3b9 refactor(logger): more consistent error output 2023-07-20 16:10:51 +10:00
Linden 4870c56045 refactor(database): general code review/cleanup 2023-07-19 23:57:20 +10:00
Linden 45aadf7442 refactor(logger): only enable profiling with debugging
Breaks slow query warnings, but most people just set the number higher
once they get warnings anyway.
Also fixes some issues:
- profile duration formatting and time (sec to ms).
- incorrect log query/param index.
2023-07-12 15:38:47 +10:00
Linden bdbe86c0f7 fix(database): handle profiles for >100 statements in batch queries
Profiling is limited to the last 100 queries on a connection.
Clearing profiles after every 100th query should work well enough.
2023-07-12 13:18:55 +10:00
Linden 51c84a30ca refactor(database/rawExecute): split batched query logs 2023-07-12 11:30:49 +10:00
Linden 197b92891a refactor(database): query profiling 2023-07-11 18:40:03 +10:00
Linden fa0068e798 refactor(database): use mysql2/promise
Better code-flow.
Other minor changes to config.
Remove profiling (temp).
2023-07-11 16:33:01 +10:00
Linden 1829ded03c fix: don't throw errors outside of promises 2023-06-18 04:14:33 +10:00
Linden 11b21f8ed2 refactor(db): rename serverReady variable 2023-06-13 02:23:33 +10:00
Linden e8f1abcab7 feat(rawExecute): "prepare" alternative without unpacking
See #179. Always return an array of row results (or null).
Parameters are now optional (though preferred).
2023-06-06 14:37:05 +10:00
Linden 5a949b9546 fix(database): throw Error before creating promise
Promises, even when resolved/rejected immediately after their creation, will
destroy any useful information from a stack trace when used over
events/exports.

Since some people still use the exports rather than MySQL/lib.lua, and for
some reason don't know the correct syntax for Lua exports (i.e. using
exports.oxmysql.query instead of the CORRECT exports.oxmysql:query) it's
comically common for an "untraceable" error to get spit out.

Will this help? No. Will everyone expect me to solve their issues? Yes.

Go update your scripts to use MySQL/lib.lua and we can all get along
stress-free.
2022-11-18 08:58:43 +11:00
Linden bc8a874743 refactor(database): waitForConnection 2022-11-08 17:29:05 +11:00
Linden 2a5e110e29 fix(database/rawExecute): append extra null values 2022-11-08 16:57:51 +11:00
Linden 25f8feb793 fix(execute): handle nil values in nested arrays
Lua tables are msgpacked with the "without_hole" setting.
Nested tables being sent with "prepare" failed to account for
nil values in tables unpacking into objects.
2022-11-08 15:17:01 +11:00
Linden d80615bddc fix(db): handle errors during callbacks
Handles errors that would previously disappear into the void or show as 'undefined'.

In Lua this would only occur if yielding during the query callback response.

Cross runtime error handling is suffering.
2022-06-26 04:02:50 +10:00
Niek fd8ab04f1a fix(error-events): Add invokingResource to error data (#129) 2022-06-26 04:01:05 +10:00
Niek 655ee7309f feature: Add event to error handling (#128) 2022-06-22 02:32:22 +10:00
Linden 15884fbc82 refactor: error handling
Meant to push this before release.
Ensures errors are handled as before, regardless of using exports
or lib/mysql; for compatibility.
2022-06-18 16:32:07 +10:00
Linden bccd6a1035 fix: error handling when using callbacks
Only allow manual error handling when using the await/sync methods,
or when calling the default exports.

Async/Callback returns need to throw errors for compatibility.
2022-06-17 21:40:27 +10:00
Linden 21e73c17b8 refactor(db/execute): mysql2 callback api
Attempt #2; last attempt had some connection issue.
Minor performance improvement, more noticeable with bulk queries.
2022-06-16 18:09:09 +10:00
Linden 340ca48012 refactor: error handling
Add boolean to disable throwing error for query.
Reject promises when using _async exports.
Return errors as strings instead of Error (fails to serialise).

Fixes #122
2022-06-04 14:50:49 +10:00
Linden 56729ef9c1 fix(db): ignore errors during ref call 2022-05-12 08:49:29 +10:00
Linden da83eff989 revert(execute): transaction api
Somebody, somewhere, will experience compatibility issues with any
change made to oxmysql.
2022-04-21 12:07:47 +10:00
Linden 050eef58b9 fix(execute): revert to promise api
Several reports of increased chances to hit a deadlock since v2.2.2, and
three reports of a timeout during prepare since v2.2.4.
Simpler to revert to the old prepare function and api (with improvements)
than to work out the solution.

Look into rewriting prepare in the future or including the mariadb connector,
which doesn't suffer from the same perf issues.
2022-04-03 06:10:13 +11:00
Linden fa1cdcc668 fix(execute): incorrect response parsing
Fixes several regressions and issues from ef0dfaa.
Sending a single parameter would set 'single' to true, ignoring multiple
results from the database and returning 'null'.
SELECT should not trigger transactions, not the other way around.
Results should not be parsed when no callback is defined.
2022-04-03 03:52:07 +11:00
Linden ef0dfaac84 refactor(execute): remove mysql2 promise api
Changing from promises to callbacks gives ~20% increased performance.
Single prepared statements won't use transactions (no extra overhead).
2022-03-30 05:54:54 +11:00
Linden 6c8934f906 perf(execute): ignore results if cb is undefined
Do not parse results when a callback argument was not received.
Minor improvements to response parsing.
2022-03-27 08:37:11 +11:00
Linden f82fa72643 fix(execute): incorrect execution time for multiple queries
When sending bulk-statements using prepare, the execution time
would always be calculated based on the start of the first query.

This would mistakenly report successive queries as taking longer,
and possibly report slow queries (i.e. when saving all players).
2022-03-27 08:32:39 +11:00
Linden 9fec9cccba refactor(execute): don't use transactions for SELECT statements 2022-03-27 07:11:00 +11:00
Linden d34bbc45f5 fix(execute): properly await all query responses 2022-03-26 00:58:27 +11:00
Linden 3582e72122 refactor(execute): use transactions and parse values
Parse each value while iterating prepared statements, ensuring
objects are remapped to arrays and NULL values are properly
inserted.

Utilise transactions to rollback changes in the event of an error.
2022-03-25 19:00:29 +11:00
Linden dea98f7c5b refactor(database): move from mysql2/promise to callback api
Micro-optimisation for rawQuery. rawExecute and rawTransaction will
still utilise the promise api (pool.promise()).
2022-03-25 06:07:57 +00:00
Linden dd05cb8e68 refactor(database): response is always a callback now 2022-03-25 05:38:18 +00:00
Linden 86d85dfa00 fix(execute): handle nil parameters in prepared statements
Lua tables are msgpacked with the 'without_hole' setting, resulting
in an object. rawQuery already handles this and converts an object
into an array (filling null where appropriate).

Give rawExecute the same treatment.
2022-03-25 04:41:39 +00:00
Linden afc04fc553 fix(db): move query responses to their own try block
Other resources with script errors (notably "attempt to index a nil value") would mistakenly report the query as failed, and people would assume ANY reported errors were because of oxmysql, even through it was their own awful script.

No errors should be thrown in oxmysql when an error occurs in a function reference.
2022-03-07 15:13:07 +11:00
Linden ec53b3282d refactor(utils/scheduleTick): Await database connection 2022-02-25 17:11:28 +11:00
Linden 2d28c447ec fix(db/rawExecute): Parse multiple returned rows 2022-02-24 10:59:12 +11:00
Linden 4975a17a31 fix(db/execute): Parse responses during prepare
Prepare should return the most appropriate result type (scalar, single, query, update, etc.)
2022-02-10 16:57:28 +11:00
dunak-debug 3a1462e0c0 fix(execute): Parse parameters as intended 2022-01-04 16:10:27 +01:00
dunak-debug 4498dddbac WIP: Rewrite to TS & Cleanup 2021-12-26 02:21:46 +01:00