Tutorial by Examples

ORDER BY x x can be any datatype. NULLs precede non-NULLs. The default is ASC (lowest to highest) Strings (VARCHAR, etc) are ordered according the COLLATION of the declaration ENUMs are ordered by the declaration order of its strings.
ORDER BY x ASC -- same as default ORDER BY x DESC -- highest to lowest ORDER BY lastname, firstname -- typical name sorting; using two columns ORDER BY submit_date DESC -- latest first ORDER BY submit_date DESC, id ASC -- latest first, but fully specifying order. ASC = ASCENDING, DESC ...
ORDER BY FIND_IN_SET(card_type, "MASTER-CARD,VISA,DISCOVER") -- sort 'MASTER-CARD' first. ORDER BY x IS NULL, x -- order by `x`, but put `NULLs` last. Custom ordering SELECT * FROM some_table WHERE id IN (118, 17, 113, 23, 72) ORDER BY FIELD(id, 118, 17, 113, 23, 72); Returns th...
Memcache is a distributed object caching system and uses key-value for storing small data. Before you start calling Memcache code into PHP, you need to make sure that it is installed. That can be done using class_exists method in php. Once it is validated that the module is installed, you start with...
When the shell performs parameter expansion, command substitution, variable or arithmetic expansion, it scans for word boundaries in the result. If any word boundary is found, then the result is split into multiple words at that position. The word boundary is defined by a shell variable IFS (Interna...
See what, when and why if you don't know about the affiliation of IFS to word splitting let's set the IFS to space character only: set -x var='I am a multiline string' IFS=' ' fun() { echo "-$1-" echo "*$2*" echo ".$3." } fun $var This time wo...
$ a='I am a string with spaces' $ [ $a = $a ] || echo "didn't match" bash: [: too many arguments didn't match [ $a = $a ] was interpreted as [ I am a string with spaces = I am a string with spaces ]. [ is the test command for which I am a string with spaces is not a single argument...
There are some cases where word splitting can be useful: Filling up array: arr=($(grep -o '[0-9]\+' file)) This will fill up arr with all numeric values found in file Looping through space separated words: words='foo bar baz' for w in $words;do echo "W: $w" done Output...
readarray -t arr <file Or with a loop: arr=() while IFS= read -r line; do arr+=("$line") done <file
while IFS= read -r line; do echo "$line" done <file If file may not include a newline at the end, then: while IFS= read -r line || [ -n "$line" ]; do echo "$line" done <file
var='line 1 line 2 line3' readarray -t arr <<< "$var" or with a loop: arr=() while IFS= read -r line; do arr+=("$line") done <<< "$var"
var='line 1 line 2 line3' while IFS= read -r line; do echo "-$line-" done <<< "$var" or readarray -t arr <<< "$var" for i in "${arr[@]}";do echo "-$i-" done
while IFS= read -r line;do echo "**$line**" done < <(ping google.com) or with a pipe: ping google.com | while IFS= read -r line;do echo "**$line**" done
Let's assume that the field separator is : (colon) in the file file. while IFS= read -d : -r field || [ -n "$field" ]; do echo "$field" done <file For a content: first : se con d: Thi rd: Fourth The output is: **first ** ** se con d** ** Thi ...
The NSString formatting supports all the format strings available on the printf ANSI-C function. The only addition made by the language is the %@ symbol used for formatting all the Objective-C objects. It is possible to format integers int myAge = 21; NSString *formattedAge = [NSString stringWith...
Let's assume that the field separator is : var='line: 1 line: 2 line3' while IFS= read -d : -r field || [ -n "$field" ]; do echo "-$field-" done <<< "$var" Output: -line- - 1 line- - 2 line3 -
Classes have instance variable (dependencies), on which they call methods. Example taken from http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html for reference public class Example { private DatabaseThingie myDatabase; public Example() { myDatabase = new DatabaseTh...
Let's assume that the field separator is : arr=() while IFS= read -d : -r field || [ -n "$field" ]; do arr+=("$field") done <file
Let's assume that the field separator is : var='1:2:3:4: newline' arr=() while IFS= read -d : -r field || [ -n "$field" ]; do arr+=("$field") done <<< "$var" echo "${arr[4]}" Output: newline
Let's assume that the field separator is : while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**" done < <(ping google.com) Or with a pipe: ping google.com | while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**&q...

Page 763 of 1336