views:

83

answers:

4

Hello, we are opening up our application to allow support for multiple languages. one of the problems we have encountered along the way is a feature we provide our customers. Imagine for a moment the user is presented with 3 fields.

  1. All customers is a toggle
  2. From Customer Name is a field they can type in
  3. To Customer Name is a field they can type in.

what happens from the user experience standpoint is if you select all customers "from" and "to" are disabled

what happens in the code is if the customer selects "all customers" we look for all customer records that have customer names greater than or equal to "" (blank) and less than or equal to "}}}}}}}}}}}}" (which works fine in ANSI).

when we put a chinese character in the first letter of the name this does not work since the code for the Chinese glyph is greater than "}". Is there a character in UTF-8 that is "the last character" so I could replace it?

We are intending on supporting multiple languages so if the solution only works for Chinese it won't help us.

Thanks Kevin

A: 

Why not use CUSTOMERNAME IS NOT NULL instead? That would allow any range of characters without worrying about what's the first and last character in any particular text encoding.

Ken White
thanks for the comments everyone. as the first comment suggested reworking the code into multiple code paths can work (one for all customers one for from and to customer filled out). this is sort of the same thought and I may end up here to solve the problem and for efficiency sake.
Kevin
A: 

I would rework the logic of the application so that you don't have to search for the names of the customers in order to get references to them.

Simply add all customers to the list of customers if the "all customers" switch is toggled on.

Alexander Kjäll
+2  A: 

When "all customers" is selected run a query without any conditions on customer name.

Yes, this means a new, alternate path of execution. Yes, it's not "smart".

At the same time it will be a lot more readable and easier to troubleshoot later. KISS

Bragi Ragnarson
+1, sometimes "smart" is over-rated
Glen
this would work but we end up with several paths (not just 2). All customers, from customer selected and to customer not selected, to customer selected but from customer not selected, from and to customer selected. the other problem is this code is everywhere (ugh) so it isn't one fix and move on.
Kevin
+1  A: 

Wouldn't it be simpler to create a base select statement with all other conditions and then add the from/to conditions based on whether the from/to fields were filled in or not? Something like this:

sql = "select a,b,c from users where c = 123";
if(!from.empty())
   sql += " and name >= '" + from + "'";
if(!to.empty())
   sql += " and name < '" + to + "'";
atk
Please. This is pseudo-code - let's treat it as such.