|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| alienz Almost An Agent ![]() Joined: 22 Mar 2004 Posts: 1436 Location: Mars ![]() ![]() |
The select does return data. It's all documented in the readme, I simply didn't assign the select to an array in the example. And none of the methods do the same thing. And, I don't take it as you saying it's bad...I know it's nothing spectacular, it's my first one LOL _________________ Check out Botworld! A dev resource for things bot. Downloads, articles, news, fourm and more. http://botworld.marzopolis.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||







| I was wrong about the selects. However all the other methods do
The only change is the name of the sub. There is no advantage to doing this over just calling ->do on the DBH. Now instead of a single ->do method you have a ton of methods. If you are planning on doing something more in there in the future then cool. Otherwise it is just adding more methods that all do one thing, execute a SQL command. DBI has that built in with ->do. Now if the insert method just took a table name, and then the row of data to insert and created the SQL for you then that would be cool. A note about the code. Since all those methods are identical you could have one method do that, and all the others call that specific method. Also if you are going to wrap DBI you should provide a means for arguments to be passed to the execute so that place holders can still be used. You don't want to teach new people not to use place holders. BTW I like the general idea. Well i like what I see as the general idea, wrapping DBI calls with good error handling. That added to being able to see where it is called from and what SQL was actualy passed could be very valuable. _________________ Eric256 Proud previous owner and current admin of Bot-depot.com |
|||



I didn't realize the ->do would execute any statement. That would've changed the way I did it in the beginning. My mistake. <_< That's something to consider for future revision.
And I did have an eye toward maybe doing more in the future there.
I agree, that would be cool..and easily done too.
I did think about this, but since you can do an insert and enter any values you want, I didn't think placeholders were needed. Some drivers don't support placeholders either.
Thanks! _________________ Check out Botworld! A dev resource for things bot. Downloads, articles, news, fourm and more. http://botworld.marzopolis.com |
|||||||||||



| Update Already working on a new version incorporating some of your suggestions. I've added ->do , and insert will create the SQL statement by getting the table, fields, and values. You'll be able to do the method a few different ways depending on whether your values are variables or hardcoded into the statement. A sample:
Thanks for the feedback. _________________ Check out Botworld! A dev resource for things bot. Downloads, articles, news, fourm and more. http://botworld.marzopolis.com |
|||



You should think about passing in a hash, where the keys are the field names and the values are the field values. This is how I do that with my Database module:
Update works basically the same way, but you supply a record ID or a WHERE clause to help you determine which record(s) to update. Just some ideas for you. |
|||







| Actualy DBI supports the placeholders and quotes the values for you in cases where the driver does not. So DBI + placeholders is a good thing regardless of what driver you are using. "but since you can do an insert and enter any values you want," That is the problem. What if you accidently got a bad value in your insert? This is called SQL injection and can be very very bad. Using placeholders protects agiants it because it will quote/escape the incomming value in such a way that it can't be used to insert SQL. _________________ Eric256 Proud previous owner and current admin of Bot-depot.com |
|



| Ok, but wouldn't injection only be bad if say, someone else could put them in? The way I currently use it, only the values I code into it are passed...there is nearly nothing that a user could inject. Generally if something doesn't match up, such as the wrong data type, etc it'll die gracefully. I like that idea mojave, but how do you get it to tell the keys are the fields and which is the values? Like for example if my insert takes the table, fields and names as separate arguments and creates the sql...how would it take the hash and separate fields/values? _________________ Check out Botworld! A dev resource for things bot. Downloads, articles, news, fourm and more. http://botworld.marzopolis.com |
|
| All times are GMT |
||