C
C#7mo 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
Buddy7mo ago
$sqlinjection
MODiX
MODiX7mo 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
Buddy7mo ago
SQL Injection is very important to know if you are messing with databases
JammyG
JammyGOP7mo ago
It's not going anywhere, its a beginner project
Buddy
Buddy7mo ago
Great to know nonetheless
JammyG
JammyGOP7mo ago
that's true
SpReeD
SpReeD7mo ago
Have you saved/wrote the changes in the SqliteBrowser?
JammyG
JammyGOP7mo ago
yeah, if I open the db file it has the table in it
Buddy
Buddy7mo ago
Where does it exist? The db file that is
SpReeD
SpReeD7mo ago
Have you selected the correct file? Tried using an absolute path? - I'm almost sure you're creating an empty DB.
JammyG
JammyGOP7mo ago
No description
Buddy
Buddy7mo ago
That's why then the database is relative to your executable location
SpReeD
SpReeD7mo ago
Since this is what the Sqlite does when it's not found, no error message, just a blank db file.
Buddy
Buddy7mo ago
Database cannot be embedded within the application unless it's an in-memory DB
JammyG
JammyGOP7mo ago
Where should I put the database? If i want it to work on another machine
Angius
Angius7mo ago
Next to the csproj and set it to copy on build
MODiX
MODiX7mo 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
Buddy7mo ago
Isn't the working directory the debug path? executable path Oh, right
Angius
Angius7mo 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
JammyGOP7mo 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
Angius7mo ago
./LoginDatabase.db should do Even LoginDatabase.db alone tbh
Buddy
Buddy7mo ago
Remember, the database will not be embedded. It must be located on disk
Angius
Angius7mo ago
So right-click on the database file and set it to be copied always
SpReeD
SpReeD7mo 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
Angius7mo 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
JammyGOP7mo ago
doing this fixes it. It works now
SpReeD
SpReeD7mo ago
hehe, but that's what the AppData is for :X
JammyG
JammyGOP7mo 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
Angius7mo ago
Sure
JammyG
JammyGOP7mo ago
Okay, thank you
Tvde1
Tvde17mo ago
when you clean + build, your data will be erased :(
Want results from more Discord servers?
Add your server