Closed cpreston321 closed 1 month ago
May I know what is the use-case for this? Because prepared statements are not supported for table names.
Now describing what happened in your case:
Case 1 which doesn't work:
DB0 thought that the name
is meant to be used as prepared statement and following query was generated:
SELECT * FROM ? LIMIT ?
. DB connector rejected that since table name is expected there.
Case 2 which does work (wrapped by braces): DB0 has took it as a static parameter (parameter which need not be passed as prepared statement). This is to allow developer to use string literals without them being passed on as connection parameters. Yes this should be documented, I will raise the PR.
If this was for demonstration, it's okay. But never send static parameters
from an untrusted source such as request. STATIC PARAMETERS ARE NOT SANITISED.
@amandesai01 I was creating a endpoint to dynamically fetch the table name e.g. GET /tables/users
then would return this to the frontend to render the table. Maybe there is a better way to go about it, but I don't want to create multiple endpoints to fetch all the tables 😅
This application I was building was to view the data on the application side and the user will select what table they want to view. Almost like DataGrip, Table Plus etc..
You must use some enums / strict validation. You may create a set of valid values and make sure value exists in set before sending it to query or whatever.
I run into this today. Thanks for the {}
solution.
Environment
Darwin
v20.10.0
3.11.1
3.11.1
2.9.5
bun@1.1.3
-
css
,devtools
,modules
,fonts
,shadcn
,eslint
,experimental
,nitro
@nuxt/fonts@0.5.1
,@nuxtjs/tailwindcss@6.11.4
,@pinia/nuxt@0.5.1
,shadcn-nuxt@0.10.2
,@nuxt/eslint@0.3.0-beta.6
-
Reproduction
I will add one here soon.
Describe the bug
Additional context
It seems to work fine if I add the
{}
around the variable but maybe that was intended and isn't documented.Logs