The patch.
2012/3/11 Ricardo Muñoz Fernández <[email protected]>:
> Hello again,
>
> 2012/3/9 Ricardo Muñoz Fernández <[email protected]>:
>> Hello! i've found a extrange behaviour related to column names and
>> binding by name. You can find the code attached to this mail.
>> I'm using postgresql backend and soci lib compiled from sourceforge git repo:
>>
>> ricardo@bugge:~/devel/git/soci(master)$ git show
>> commit 631977adad434bcbdf0b8ee30314fa886757e4b0
>> Merge: 901e1ba 6e45bdb
>> Author: Mateusz Loskot <[email protected]>
>> Date: Sat Feb 25 09:22:10 2012 -0800
>>
>> I have a table with 4 columns: id, firstName, lastName, idcard and
>> streeet. When i try to update a row with:
>>
>> st = (sql.prepare << "UPDATE persons SET firstName = :firstName,"
>> " lastName = :lastName, idcard = :idcard, street = :street"
>> " WHERE id = :id",
>> use(p));
>>
>> And execute the code i get an error: "Error: Missing use element for
>> bind by name (id)"
>>
>> If i change all occurrences of "idcard" by "card" in the code, it works.
>>
>> Its a bug or i'm doing something wrong?
>
> I was debugging soci to understand what happens under the hood, and i
> found the reason of described behaviour on statement_impl::bind(values
> & values) (core/statement.cpp).
>
> On line 101: query_.find(placeholder) returns the first occurrence of
> ":id", that match with :idcard word on the query, and not with the
> desired match on WHERE clause:
>
> UPDATE persons SET firstName = :firstName, lastName = :lastName,
> idcard = :idcard, street = :street WHERE id = :id
>
> So thats the reason of changing idcard by card, solves the problem.
> I've tried to fix it using a while loop (patch attached), and it
> founds all placeholders but i get a segmentation fault later.
>
> It's the first time that i get into soci's code so i feel a little bit
> lost. If any developer can give some guidance i will try to fix it (if
> you consider it a bug), for the moment, I workaround it changing my
> naming scheme to avoid multiple matches.
>
> HTH, regards
> --
> Ricardo Muñoz Fernández
> Warp Networks S.L. - http://www.warp.es
> Zentyal - http://www.zentyal.com
--
Ricardo Muñoz Fernández
Warp Networks S.L. - http://www.warp.es
Zentyal - http://www.zentyal.com
diff --git a/src/core/statement.cpp b/src/core/statement.cpp
index f5f7e3a..7ab797b 100644
--- a/src/core/statement.cpp
+++ b/src/core/statement.cpp
@@ -98,8 +98,8 @@ void statement_impl::bind(values & values)
// named use element - check if it is used
std::string const placeholder = ":" + useName;
- std::size_t const pos = query_.find(placeholder);
- if (pos != std::string::npos)
+ std::size_t pos = query_.find(placeholder);
+ while(pos != std::string::npos)
{
const char nextChar = query_[pos + placeholder.size()];
if (nextChar == ' ' || nextChar == ',' ||
@@ -109,13 +109,15 @@ void statement_impl::bind(values & values)
(*it)->bind(*this, position);
uses_.push_back(*it);
indicators_.push_back(values.indicators_[cnt]);
+ pos = std::string::npos;
}
else
{
- values.add_unused(*it, values.indicators_[cnt]);
+ pos = query_.find(placeholder, pos + 1);
}
}
- else
+
+ if (pos == std::string::npos)
{
values.add_unused(*it, values.indicators_[cnt]);
}
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users