-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Sanitization of enumerable arguments in [FMDatabase executeQuery:withArgumentsInArray:] #180
Conversation
…ort for NSArray arguments.
No comment on this yet, because I'm still thinking about it. (Though if I do accept something like this, the ? placeholder would have to be changed to something else. In sqlite, ? has a well defined meaning already, and shouldn't represent multiple placeholders) |
When a user binds a collection (array, set) to a The binding of collections is, today, meaningless. You can see my contribution as a way to fill this hole. Would you want to reserve the binding of collections to something else in the future, I would understand your questionning. I claim that my proposal is, at least, natural and unsurprising, not mentioning helpful. |
…port for NSArray arguments.
Hi @ccgus. I've added support for BOOL success = [db executeUpdate:@"UPDATE table SET column = ? WHERE id IN (?)" withArgumentsInArray:@[value, ids]]; I hope you will agree it's convenient... |
What's up? |
@groue I like the fact that even if you can't handle But, I can't help but think this might be better suited as an external category. It seems like such a deviation of standard SQLite binding syntax that it doesn't feel like it belongs in the core FMDB, to me. And there have been other pull requests that attempt to parse SQL (for very different purposes), and I think those are best suited as separate categories, too. By the way, if this pull request gets merged, I'd suggest also updating the comments in the .h so it bears a warning about the non-standard SQL syntax as well as the limitation of |
A light of hope ;-) All right, I'll perform the requested cleanup in the next days. |
@groue You really should wait to hear from Gus (who, as I understand, is moving and is therefore occupied with other matters right now) before investing any time here. I'm just an interested observer, with no authority to say what pull requests get merged and which don't. I was just giving you my two cents. |
So I've had a couple of personal requests for this as well (and yes, maybe as a category?). But what should the syntax be for the placeholder? '??' maybe? '@?', ? Any ideas? |
Two more ideas:
I kind of like |
I like |
A bit of context:
It looks like you are not convinced about the utility of this PR. When you invent a new syntax, a syntax that nobody knows about, a syntax that will be documented in some burried side of the documentation, you are making the feature nearly undiscoverable, the use case an ultra-minor one, and people will keep on expanding their arrays into A special syntax would kill the spirit of this PR, which is helping people who fill SQL with Objective-C objects. We are all trying to have a sensible and solid discussion, right? I hope you will see the previous point as valid. Reminder: today, when a user binds a collection to a
This string is itself interpreted by sqlite as It can not be what the end user, the developer, wants. I'm disappointed that none of you has yet agreed on this. This is thus a programmer error: it actually deserves an exception. I'm disappointed that none of you has seen this point. This leaves the I'm disappointed that none of you has gone to this logical conclusion, or, at least, has agreed that it it indeed a valid point. You invoke the "respect of the sqlite syntax". Except that sqlite doesn't say anything about collection binding. As a conclusion, I claim that Do whatever you want with this. |
@ccgus wrote:
@ahti wrote:
@newyankeecodeshop wrote:
You have my answer above. @newyankeecodeshop wrote:
This is an interesting proposal. It may need to be refined. Let's look at how other libraries identify collections: My own GRMustache library (a template engine) doesn't check NSFastEnumeration conformance, but checks whether objects respond to Handlebars-objc (another template engine) has a special case for NSArray, NSOrderedSet and NSSet, plus checks for both NSFastEnumeration conformance and the |
@ccgus have you come to a conclusion regarding this issue? I keep running into it again and again. Imho, this is really a quite big usability issue with FMDB. |
I haven't had a chance play with it yet, sorry. Just don't pass collection types into a prepared statement for now. |
Now that I have shipped a Swift toolkit for SQLite (heavily influenced by fmdb), I have a better understanding of @ccgus' reluctance to accept this. FMDB does not focus at all on reusable SQLite statements, and I missed them. But reusable statements are a big drag for transparent support for array bindings. @ccgus : it was a strong decision to hide reusable statements from fmdb API. And I have never missed them, even though I knew that such a concept existed. So this decision of yours was probably the good one. Do you remember why you took this path? |
Do you mean the decision to "hide" reusable statements, or not accepting this PR? I don't think I'm hiding reusable statements, I just have them off by default because I think the programmer should know what she/he getting into before turning it on. As for not accepting the PR - there's just a little "code smell" about it that's tripping warnings in my head. |
Definitely the decision to "hide" reusable statements, which I do not question at all.
If I understand well your sentence, there is a fmdb API to reusable statements that the programmer can turn on. Is it true? |
FMDatabase's - (void)setShouldCacheStatements:(BOOL)value; |
Thanks for the info, @ccgus. |
Hi,
This commit provides data sanitization of NSArray, NSSet and NSOrderedSet arguments in [FMDatabase executeQuery:withArgumentsInArray:], and solves two problems:
For example:
There are a few caveats, though. They are documented in the method implementation (see attached code).
I hope you'll find this patch useful, and that we'll improve it together.