Commit Graph
33 Commits
Author SHA1 Message Date
Linden fbc2542136 fix(utils/parseTransaction): properly handle arrays of queries 2023-07-19 20:16:23 +10:00
Linden f3401eb671 fix(config): export convertNamedPlaceholders
parseArguments relied on options.namedPlaceholders, which is now always false.
Function is now exported directly when enabled (+typed).
2023-07-19 14:29:21 +10:00
Linden b2387fc33a refactor: minor tweaks and cleanup
Primarily moving connectionOptions fully to config.
Removed exported resource name.
Include error code and number when database connection fails.
2023-07-12 00:05:29 +10:00
Linden 0caaec43e4 fix(utils/parseExecute): only set undefined parameters to null
Falsey values (e.g. empty string) should not be set as null.
2023-07-06 12:56:44 +10:00
Linden 8a340d60e3 refactor(utils/parseExecute): allow other methods through prepare calls 2023-07-06 12:52:14 +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 283e3194cf fix(utils/parseExecute): incorrect parameter reassignment 2022-11-08 16:57:02 +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 ff00cd0e82 fix(utils/parseArguments): check parameter truthiness 2022-08-24 18:41:05 +10:00
Linden f0dd9ce1a6 fix(utils): named placeholders check
Should always check parameters is an object (and not an array).
2022-08-13 17:12:48 +10:00
Linden 71c32f9d2f tweak(utils): check if namedPlaceholders are enabled
Named placeholders were being converted regardless of config flag.
2022-08-13 16:23:47 +10:00
Linden db0f29db42 fix(utils/parseTransaction): check for array 2022-06-26 04:01:11 +10:00
Linden db5fe3e557 fix(utils/parseExecute): executeType fails when query has multiple lines 2022-05-15 03:25:41 +10:00
Linden c07fa4a451 refactor(transaction): support new transaction syntax
Adds a third accepted syntax for transactions, distinct from the mysql-async
compatible implementations.
2022-04-21 13:25:40 +10:00
Linden 9ef9b0d8c9 fix(utils/typeCast): typeerror
BLOB's with a value of null cannot be iterated, resulting in an
error while trying to return [...field.buffer()].
Minor change to weird typecasting on date values.
2022-04-02 19:52:58 +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 9fec9cccba refactor(execute): don't use transactions for SELECT statements 2022-03-27 07:11:00 +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 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 cd62fdd904 refactor(utils/parseArguments): Reduce redundant assignments
More in-line with 1.9.3 parser; reduced garbage and improved performance. Should handle JSON better.
2022-03-02 23:24:52 +11:00
Linden 9e50d8ddd0 fix(utils/parseArguments): Missing type check 2022-02-28 16:01:08 +11:00
Linden ec53b3282d refactor(utils/scheduleTick): Await database connection 2022-02-25 17:11:28 +11:00
Linden e29ca87c98 fix(utils): Do not convert placeholders if query contains JSON 2022-02-24 10:24:27 +11:00
Jaime Filho 8611cc0762 fix: Add charset to cast binary and json data correctly 2022-02-18 19:12:46 -03:00
Linden 2ea78f1b1b Merge branch 'refactor' into main 2022-02-14 22:23:28 +11:00
Linden 3cfa080cfc fix(utils/typeCast): Ensure field.packet is defined
Apparently this can be undefined.
2022-02-11 05:15:29 +11:00
Linden 7096237ce2 refactor(utils/typeCast): Change BIT and BLOB types
BIT fields should only cast as boolean if they have a length of 1.
2022-02-10 17:23:42 +11:00
erik.balog 38e30c6640 fix: Scalar return value 2022-01-23 13:10:34 +01:00
dunak-debug 21ded71fde fix: Return correct scalar value 2022-01-07 23:41:11 +01:00
dunak-debug 4498dddbac WIP: Rewrite to TS & Cleanup 2021-12-26 02:21:46 +01:00