C
C#8mo ago
JammyG

no such table

I'm not sure why i'm getting this, I do have a table called users. Am I formatting the query wrong?
No description
No description
31 Replies
Buddy
Buddy8mo ago
$sqlinjection
MODiX
MODiX8mo ago
Always parametrize queries! Do not concatenate the query, like in this example:
// Do NOT do this
string query = "SELECT * FROM users WHERE username='" + UserName + "';";
...
// Do NOT do this
string query = "SELECT * FROM users WHERE username='" + UserName + "';";
...
Instead, always parameterize your queries. Look up the documentation for your database library. If you are using System.Data.SqlClient, refer to this example.
Imgur
Buddy
Buddy8mo ago
SQL Injection is very important to know if you are messing with databases
JammyG
JammyGOP8mo ago
It's not going anywhere, its a beginner project
Buddy
Buddy8mo ago
Great to know nonetheless
JammyG
JammyGOP8mo ago
that's true
SpReeD
SpReeD8mo ago
Have you saved/wrote the changes in the SqliteBrowser?
JammyG
JammyGOP8mo ago
yeah, if I open the db file it has the table in it
Buddy
Buddy8mo ago
Where does it exist? The db file that is
SpReeD
SpReeD8mo ago
Have you selected the correct file? Tried using an absolute path? - I'm almost sure you're creating an empty DB.
JammyG
JammyGOP8mo ago
No description
Buddy
Buddy8mo ago
That's why then the database is relative to your executable location
SpReeD
SpReeD8mo ago
Since this is what the Sqlite does when it's not found, no error message, just a blank db file.
Buddy
Buddy8mo ago
Database cannot be embedded within the application unless it's an in-memory DB
JammyG
JammyGOP8mo ago
Where should I put the database? If i want it to work on another machine
Angius
Angius8mo ago
Next to the csproj and set it to copy on build
MODiX
MODiX8mo ago
Buddy
the database is relative to your executable location
Quoted by
<@203166497198047232> from #no such table (click here)
React with ❌ to remove this embed.
Buddy
Buddy8mo ago
Isn't the working directory the debug path? executable path Oh, right
Angius
Angius8mo ago
Unless you changed it manually, the relative path to the csproj is the same as relative path to the exe when built So
Foo
|— Foo.csproj
|— Program.cs
|— Database.db
Foo
|— Foo.csproj
|— Program.cs
|— Database.db
becomes
Foo
|— Foo.exe
|— Database.db
Foo
|— Foo.exe
|— Database.db
JammyG
JammyGOP8mo ago
it works when it's like this, with the full path. How can I format the path so it is relative
No description
No description
Angius
Angius8mo ago
./LoginDatabase.db should do Even LoginDatabase.db alone tbh
Buddy
Buddy8mo ago
Remember, the database will not be embedded. It must be located on disk
Angius
Angius8mo ago
So right-click on the database file and set it to be copied always
SpReeD
SpReeD8mo ago
Or you can create a blank the file in the AppData folder and execute the SQL statements for the structure. Then you don't depend on anything and the structure is hardcoded/embedded in your application. ¯\_(ツ)_/¯
Angius
Angius8mo ago
Or better yet, have it create that file on first run in the same directory as the exe Might be my bias speaking, though. I fucking hate it when apps cram everything and their mother onto the C: drive Looking at you, my 18 GB Space Engineers mod folder that I had to symlink
JammyG
JammyGOP8mo ago
doing this fixes it. It works now
SpReeD
SpReeD8mo ago
hehe, but that's what the AppData is for :X
JammyG
JammyGOP8mo ago
i'm not entirely sure why/ whats going on behind the scenes though. Will these be fine to do for a small database?
Angius
Angius8mo ago
Sure
JammyG
JammyGOP8mo ago
Okay, thank you
Tvde1
Tvde18mo ago
when you clean + build, your data will be erased :(
Want results from more Discord servers?
Add your server