✅ MySQL Database Procedure Problem
Heyo :)
I'm creating this post to get some assistance around database procedures and creating the necessary data without conflicting already defined parameters. The code below is not optimized yet, i'm still fixing the problem I currently have before I optimize it. Any help is appreciated!
33 Replies
so yeah, i was removing chunks of code and removed comments to reducee the character-count to ~4000 but eh, seems like discord has a good way of displaying this message :Kek:
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/oo, i see.
BlazeBin - cdytfyvcbjhv
A tool for sharing your source code with the world!
i think that should do the trick. thank you mtreit :)
What's your actual question about the code?
So the issue i'm currently experience is the way I'm inserting data into the database. As you can see, i'm basically adding the same parameters for each role/channel which causes an exception for already defined parameters. The solution I guess for this would be to use a
for
loop and apply an index number at each parameter but that wouldn't work as my procedure has a fixed parameter name and doesn't support (atm) p_role_id_1
for instance. This causes parameter p_role_id_x not defined
exception
i've barely worked with databases but I'd like to get back into it.
so yeah i have a hard time trying to do it the right way idk how :Loopy_sadge:You need to call the sproc multiple times.
One for each channel or whatever.
that's actually something I tried (maybe in the wrong way) but I believe calling the sproc would expect all parameters to be called again, no?
Create a new SqlCommand for each call.
so for the loop, create a new SqlCommand
I would probably completely refactor this code.
yes, it's very unorganized i'll be fair :Sadge:
i just wanna try to fix this issue and then re-factor it using the proper way of implementation
You probably want something like:
Are you actually intending to create multiple guilds?
yes, my integration will be storing data for each guild.
something like this perchance?
Sure, I just stuck that in as pseudo-code, you don't necessarily need to make a method for that - although it usually is cleaner and easy to read if you make small methods and chain them together in your overall flow.
got it okay, i was under the impression that creating another instance of a MySqlCommand and calling the procedure would mean that it expects all parameters to be called in one.
So if I was to say use a small helper method, I could do:
damn 😭 didn't expect the code to be so long LOL
Why don't you have separate sprocs for creating roles vs. creating channels?
spCreateChannel
spCreateRole
I was hoping to do this in one but I think separation would probably make it easier
Yes it would 🙂
you're definitely right.
since I never worked with databases, do you think I could do this:
ofc i would separate those and create individual procs for those.
And you can break that code up into more methods like:
yes, i was planning to make methods for those.
In your stored procedure? Sure.
correct.
i think the problem was to store all the
INSERT INTO
statements into a single procedure thus upon call it expects all parameters to be passed in with each new SqlCommand being created and called.
so I think for future resolutions, if I know for certain that I'm expecting things like channel/roles and perhaps even users, to break those up into procedures so I can call them individually where needed whilst keeping my code clean.
thank you mtreit :Pat_good_pet:$close
If you have no further questions, please use /close to mark the forum thread as answered
@kyeede
hello, yes?
$close
If you have no further questions, please use /close to mark the forum thread as answered