Tutorial by Examples

@Entity class Note { @Id Integer id; @Basic String note; @Transient String parsedNote; String readParsedNote() { if (parsedNote == null) { /* initialize from note */ } return parsedNote; } } If your class needs fields that should ...
Suppose we want to get all product categories with total sales greater than 20. Here is a query without Common Table Expressions: SELECT category.description, sum(product.price) as total_sales FROM sale LEFT JOIN product on sale.product_id = product.id LEFT JOIN category on product.category_id ...
Suppose we want to query the "cheapest products" from the "top categories". Here is an example of query using Common Table Expressions -- all_sales: just a simple SELECT with all the needed JOINS WITH all_sales AS ( SELECT product.price as product_price, category.id a...
SELECT x, ... FROM ( SELECT y, ... FROM ... ) AS a JOIN tbl ON tbl.x = a.y WHERE ... This will evaluate the subquery into a temp table, then JOIN that to tbl. Prior to 5.6, there could not be an index on the temp table. So, this was potentially very inefficient: SELECT ... ...
For...Next Using the iterator variable as the index number is the fastest way to iterate the elements of an array: Dim items As Variant items = Array(0, 1, 2, 3) Dim index As Integer For index = LBound(items) To UBound(items) 'assumes value can be implicitly converted to a String: D...
R is full of functions, it is after all a functional programming language, but sometimes the precise function you need isn't provided in the Base resources. You could conceivably install a package containing the function, but maybe your requirements are just so specific that no pre-made function fit...
An anonymous function is, as the name implies, not assigned a name. This can be useful when the function is a part of a larger operation, but in itself does not take much place. One frequent use-case for anonymous functions is within the *apply family of Base functions. Calculate the root mean squ...
Skip lists are linked lists that allow you to skip to the correct node. This is a method which is way more fast than a normal singly linked list. It is basically a singly linked list but the pointers not going from one node to the next node, but skipping few nodes. Thus the name "Skip List&quo...
Partial method consists of the definition in one partial class declaration (as a common scenario - in the auto-generated one) and the implementation in another partial class declaration. using System; namespace PartialClassAndMethods { public partial class PartialClass // Auto-generated ...
TRUNCATE tableName; This will delete all the data and reset AUTO_INCREMENT index. It's much faster than DELETE FROM tableName on a huge dataset. It can be very useful during development/testing. When you truncate a table SQL server doesn't delete the data, it drops the table and recreates it, th...
Blocks are chunks of code enclosed between braces {} (usually for single-line blocks) or do..end (used for multi-line blocks). 5.times { puts "Hello world" } # recommended style for single line blocks 5.times do print "Hello " puts "world" end # recomme...
With a column of one of the string types, named my_date_field with a value such as [the string] 07/25/2016, the following statement demonstrates the use of the STR_TO_DATE function: SELECT STR_TO_DATE(my_date_field, '%m/%d/%Y') FROM my_table; You could use this function as part of WHERE clause a...
The switch structure performs the same function as a series of if statements, but can do the job in fewer lines of code. The value to be tested, as defined in the switch statement, is compared for equality with the values in each of the case statements until a match is found and the code in that blo...
Objective c: //this is the dictionary you start with. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"name1", @"Sam",@"name2", @"Sanju",nil]; //check if the dictionary contains the key you are going to modify. In this example, @&qu...
The following will echo each line in the file C:\scripts\testFile.txt. Blank lines will not be processed. for /F "tokens=*" %%A in (C:\scripts\testFile.txt) do ( echo %%A rem do other stuff here ) More advanced example shows, how derived in FOR loop from a restricted files set...
From command line: cpan -l From a Perl script: use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); my @modules = $inst->modules();
wildcard characters are used with the SQL LIKE operator. SQL wildcards are used to search for data within a table. Wildcards in SQL are:%, _, [charlist], [^charlist] % - A substitute for zero or more characters Eg: //selects all customers with a City starting with "Lo" SEL...
Simple one-liners may be specified as command line arguments to perl using the -e switch (think "execute"): perl -e'print "Hello, World!\n"' Due to Windows quoting rules you can't use single-quoted strings but have to use one of these variants: perl -e"print qq(Hello, W...
Windows uses only double quotes to wrap command line parameters. In order to use double quotes in perl one-liner (i.e. to print a string with an interpolated variable), you have to escape them with backslashes: perl -e "my $greeting = 'Hello'; print \"$greeting, world!\n\"" T...
perl -ne'print if /foo/' file.txt Case-insensitive: perl -ne'print if /foo/i' file.txt

Page 491 of 1336