|
ConditionsThe condition part of the query, as shown in the "syntax" paragraph is a boolean expression, usually arbitrarily complex (old versions of MiniSQL have heavy limitations the syntax of this portion). Only rows that satisfy it will appear in the results set. If none does, the results set will be empty. When evaluating the condition, column names are substituted with the data they contain, and operators are evaluated according to a well-specified grammar. Constants must be quoted according to their type. Numeric ConstantsInteger and floating-point numbers are not quoted. They can be told apart because floating-point numbers have the decimal separator (.). Usually the server's parser is quite lenient though, fixing types when possible according to the context. Column NamesThese are not quoted. Since they mustn't be ambiguous this poses a bit of limitations on column names. As a general rule, legal C variable names are legal column names (unless they are reserved words of course). SQL is a bit more lenient than C, so you should get a little more leeway. String Constants and QuotingStrings are quoted using the apostrophe symbol ('). If a string contains the literal apostrophe character, it must be escaped. Different escaping schemes are specified, the most usual ones being doubling it (i.e. 'It''s a shame') or prepending it with a backslash (i.e. 'It\'s a shame'). Let's obtain from our sample database the total area of Italy. With RXML:
Other Data TypesOther data types are usually represented as formatted string, which get interpreted by the server according to the context. The LIKE OperatorThis operator is used to do glob-like matching. It has the syntax value *LIKE* PATTERN where the value is usually a column, and the pattern a string literal, possibly containing two magic characters: '_' and '%', which act like glob characters '?' and '*', that is they match any (single) character, and any arbitrarily long sequence of any character. If what you're matching against contains the literal '_' or '%' characters, you can escape them prepending the backslash character '\'. Let's try to find out the countries neighbouring Italy. The right way to do so would be looking in the 'boundaries' table. But a summary can be found in the countries.location text, and we'll use that. With RXML:
Notice that the "column like '%something%'" syntax (with leading and tailing globs) is very inefficient, and should be avoided whenever possible. MySQL offers the more powerful REGEXP operator, with the syntax value REGEXP expression where the value is usually a column name or a function result, and expression is a string-quoted regular expression NULL Column ValuesSome columns can be empty, or (in SQL terms) be NULL. To deal with them when selecting data, you use the 'IS' syntax, which takes the form value IS [NOT] NULL where value can be obtained from a a column (thus be a column name) or can be a constant value (of course it would be rather dumb to evaluate a constant expression, but you can of course do that if you wish). |
|||||||