Pages

12/05/2013

ยกเลิกการเกณฑ์ทหารในไทย อีกหนึ่งข้อสงสัยที่ยังไม่ยุติ

ยกเลิกการเกณฑ์ทหารในไทย อีกหนึ่งข้อสงสัยที่ยังไม่ยุติ





เรียบเรียงข้อมูลโดยกระปุกดอทคอม


                สำหรับหลายๆ คน ที่เข้าข่ายต้องเกณฑ์ทหาร หรืออยู่ในแวดวงทหารไทย ย่อมต้องเคยได้ยินข่าวลือเรื่อง ยกเลิกการเกณฑ์ทหาร มาบ้าง แต่บางคนอาจยังไม่เคยได้ยินข่าวดังกล่าวมาก่อนหน้านี้ ดังนั้นกระปุกดอทคอมจึงได้รวบรวมข้อมูลเกี่ยวกับเรื่องนี้มาฝากกันค่ะ ก่อนอื่นเรามาดูรายละเอียดคร่าว ๆ เกี่ยวกับการเกณฑ์ทหารกันก่อนนะคะ

               เกณฑ์ทหาร (Conscription) คือ การเรียกใช้แรงงานอย่างไม่สมัครใจโดยฝ่ายปกครอง โดยมีรายงานว่าในหลายประเทศได้ยกเลิกการเกณฑ์ทหารไปแล้ว เช่น สหรัฐอเมริกา ฝรั่งเศส ญี่ปุ่น สเปน เบลเยียม โครเอเชีย เลบานอน นิวซีแลนด์ โรมาเนีย เลบานอน โปแลนด์ นิวซีแลนด์ เนเธอร์แลนด์ ออสเตรเลีย เป็นต้น ส่วนประเทศที่ยังคงมีการเกณฑ์ทหารอยู่ เช่น จีน ภูฏาน ไทย อัลจีเรีย อิสราเอล (ทั้งชายและหญิง) เกาหลีเหนือ เกาหลีใต้ คิวบา (ทั้งชายและหญิง) และอิหร่าน เป็นต้น

              เหตุผลที่ในบางประเทศได้มีการยกเลิกการเกณฑ์ทหาร หรือยังคงมีการเกณฑ์ทหารอยู่ อาจขึ้นอยู่กับปัจจัยหลายประการ โดยในบางประเทศได้มองข้อเสียของการเกณฑ์ทหารว่า ทำให้เกิดความความสิ้นเปลืองทางเศรษฐกิจในยามที่ประเทศสงบสุข อีกทั้งยังขัดกับปฏิญญาสากล ว่าด้วยสิทธิมนุษยชน รวมถึงขัดกับเสรีภาพของประชาชน

             ขณะที่ในบางประเทศมองว่า การเกณฑ์ทหารมีข้อดี คือ เป็นการเตรียมพร้อมสำหรับประเทศที่ยังมีภาวะสงคราม หรือคาดว่าอาจจะเกิดสงครามได้ในอนาคต ทั้งนี้ พบว่า หากประเทศที่ยกเลิกการเกณฑ์ทหารแล้วได้เกิดภาวะฉุกเฉิน หรือมีภาวะสงครามเกิดขึ้น ประเทศเหล่านั้นจะอาศัยกองกำลังทหารอาชีพและอาสาสมัครเข้ามาช่วยจัดการความสงบเรียบร้อยเป็นการชั่วคราว

            ทั้งนี้ เรื่องการยกเลิกการเกณฑ์ทหารในประเทศไทยนั้น ไม่มีที่มาระบุแน่ชัดว่าข่าวดังกล่าวมาจากแหล่งใด แต่ล่าสุด เมื่อวันที่ 4 มกราคม 2556 ที่ผ่านมา ผู้ใช้บัญชีเฟซบุ๊ก นายหอกลอง ณ. สนามหลวง ที่มักเผยแพร่ข่าวสารของกระทรวงกลาโหม ได้โพสต์ข้อความระบุว่า “กระทรวงกลาโหม (โดยกรมการสรรพกำลังกลาโหม) เตรียมศึกษาระบบการเกณฑ์ทหาร เพื่อปรับเปลี่ยนจากการเกณฑ์เป็นแบบสมัครใจ ตามแนวทางการพัฒนาระบบกำลังสำรอง ของรัฐมนตรีว่าการกระทรวงกลาโหม เพื่อให้ได้ทหารกองประจำการ (ทหารเกณฑ์) ที่มีประสิทธิภาพ มีความต้องการที่จะเป็นทหารอย่างแท้จริง เรื่องนี้ถ้าสำเร็จนอกจากจะแก้ปัญหาคนหนีทหารได้แล้ว ยังได้ทหารอาชีพมาทำงานอีกด้วย”

            อย่างไรก็ตาม แม้เฟซบุ๊กดังกล่าวไม่มีการยืนยันแหล่งที่มาของข่าวอย่างชัดเจน แต่ประเด็นข่าวนี้ได้สร้างความสนใจให้กับหลายฝ่าย เนื่องจากในปัจจุบันได้มีผู้แสดงความคิดเห็นว่าต้องการให้มีการยกเลิกการเกณฑ์ทหารในประเทศไทยเกิดขึ้น เช่น มีการตั้ง เฟซบุ๊ก Abolish Conscription in Thailand! ยกเลิกการเกณฑ์ทหารในประเทศไทย  โดยมีจำนวนผู้กดไลค์เพื่อติดตามแฟนเพจดังกล่าว ประมาณพันกว่าคน (8 มกราคม)
                ดังนั้น อาจกล่าวได้ว่า การยกเลิกการเกณฑ์ทหาร น่าจะมาจากความต้องการของผู้ที่เห็นค้านในเรื่องดังกล่าว และต้องการให้เรื่องนี้เกิดขึ้นในประเทศไทย แต่จากการนำเสนอข่าวของ  เฟซบุ๊ก นายหอกลอง ณ. สนามหลวง ) ถือว่าน่าสนใจเป็นอย่างมาก และเชื่อว่าหากเรื่องดังกล่าวมีความคืบหน้าใด ๆ กระทรวงกลาโหม น่าจะมีการแถลงข่าวให้ทราบข้อมูลความคืบหน้ามากกว่านี้ ดังนั้นคงต้องติดตามดูกันต่อไปว่า การยกเลิกการเกณฑ์ทหารในประเทศไทยนั้น จะมีแนวโน้มที่จะเกิดขึ้นในอนาคตหรือไม่



SingleOrDefault() Vs. FirstOrDefault() in LINQ Query

SingleOrDefault() Vs. FirstOrDefault() in LINQ Query



Single() / SingleOrDefault()

First () / FirstOrDefault()
Single() - There is exactly 1 result, an exception is thrown if no result is returned or more than one result. 
SingleOrDefault() – Same as Single(), but it can handle the null value.
First() - There is at least one result, an exception is thrown if no result is returned.
FirstOrDefault() - Same as First(), but not thrown any exception or return null when there is no result.
Single() asserts that one and only one element exists in the sequence.
First() simply gives you the first one.
When to use
Use Single / SingleOrDefault() when you sure there is only one record present in database or you can say if you querying on database with help of primary key of table.
When to use
Developer may use First () / FirstOrDefault() anywhere,  when they required single value from collection or database.
Single() or SingleOrDefault() will generate a regular TSQL like "SELECT ...".
The First() or FirstOrDefault() method will generate the TSQL statment like "SELECT TOP 1..."
In the case of Fist / FirstOrDefault, only one row is retrieved from the database so it performs slightly better than single / SingleOrDefault. such a small difference is hardly noticeable but when table contain large number of column and row, at this time performance is noticeable.
SingleOrDefault() Vs. FirstOrDefault() in LINQ Query

linq.js - LINQ for JavaScript

Project Description
linq.js - LINQ for JavaScript

Features
  • implement all .NET 4.0 methods and many extra methods (inspiration from Rx, Achiral, Haskell, Ruby, etc...)
  • complete lazy evaluation
  • full IntelliSense support for VisualStudio
  • two versions - linq.js and jquery.linq.js (jQuery plugin)
  • support Windows Script Host
  • binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator -> see documentation
  • NuGet install support(linq.js, linq.js-jQuery, linq.js-Bindings)

90 Methods

Aggregate, All, Alternate, Any, Average, BufferWithCount, CascadeBreadthFirst, CascadeDepthFirst, Catch, Choice, Concat,
Contains, Count, Cycle, DefaultIfEmpty, Distinct, Do, ElementAt, ElementAtOrDefault, Empty, Except, Finally, First, FirstOrDefault, 
Flatten, ForEach, Force, From, Generate, GetEnumerator, GroupBy, GroupJoin, IndexOf, Insert, Intersect, Join, Last, LastIndexOf,
LastOrDefault, Let, Matches, Max, MaxBy, MemoizeAll, Min, MinBy, OfType, OrderBy, OrderByDescending, Pairwise, PartitionBy, 
Range, RangeDown, RangeTo, Repeat, RepeatWithFinalize, Return, Reverse, Scan, Select, SelectMany, SequenceEqual, Share, Shuffle,
Single, SingleOrDefault, Skip, SkipWhile, Sum, Take, TakeExceptLast, TakeFromLast, TakeWhile, ThenBy, ThenByDescending, ToArray,
ToDictionary, ToInfinity,ToJSON, ToLookup, ToNegativeInfinity, ToObject, ToString, Trace, Unfold, Union, Where, Write, WriteLine, Zip

Starting linq.js ver.3.0.0-beta!(2012/07/19)

Get the ver.3.0.4-Beta5 @2013/06/20
or NuGet Install-Package linq.js -Pre, linq.js-jQuery -Pre, linq.js-RxJS -Pre, linq.js-QUnit -Pre
Now TypeScript Generics(0.9) support!

Please try it! and give me a feedback!
http://linqjs.codeplex.com/discussions/376207

Query objects or json

  • sample from http://twitter.com/statuses/public_timeline.json
var jsonArray = [
    { "user": { "id": 100, "screen_name": "d_linq" }, "text": "to objects" },
    { "user": { "id": 130, "screen_name": "c_bill" }, "text": "g" },
    { "user": { "id": 155, "screen_name": "b_mskk" }, "text": "kabushiki kaisha" },
    { "user": { "id": 301, "screen_name": "a_xbox" }, "text": "halo reach" }
]
// ["b_mskk:kabushiki kaisha", "c_bill:g", "d_linq:to objects"]
var queryResult = Enumerable.From(jsonArray)
    .Where(function (x) { return x.user.id < 200 })
    .OrderBy(function (x) { return x.user.screen_name })
    .Select(function (x) { return x.user.screen_name + ':' + x.text })
    .ToArray();
// shortcut! string lambda selector
var queryResult2 = Enumerable.From(jsonArray)
    .Where("$.user.id < 200")
    .OrderBy("$.user.screen_name")
    .Select("$.user.screen_name + ':' + $.text")
    .ToArray();

High compatibility with C# Linq

// C# LINQ (delegate)
Enumerable.Range(1, 10)
    .Where(delegate(int i) { return i % 3 == 0; })
    .Select(delegate(int i) { return i * 10; });
// linq.js - anonymous function
Enumerable.Range(1, 10)
    .Where(function(i) { return i % 3 == 0; })
    .Select(function(i) { return i * 10; });
// C# LINQ (lambda)
Enumerable.Range(1, 10).Where(i => i % 3 == 0).Select(i => i * 10);
// linq.js - lambda expression
Enumerable.Range(1, 10).Where("i => i % 3 == 0").Select("i => i * 10");
// $ is default iterator variable like Scala's "_" or Groovy's "it"
Enumerable.Range(1, 10).Where("$ % 3 == 0").Select("$ * 10");
 // "" is shorthand of "x => x" (identity function)
Enumerable.Range(4, 7).Join(Enumerable.Range(8, 5), "", "", "outer,inner=>outer*inner");

// Enumerable.From is wrap from primitive array, string(to charArray), object(to KeyValuePair[]) etc..
var array = [100, 200, 30, 40, 500, 40, 200];
var ex1 = Enumerable.From(array).Distinct().ToArray(); // [100, 200, 30, 40, 500]
var ex2 = Enumerable.From("foobar").ToArray(); // ["f", "o", "o", "b", "a", "r"];
var ex3 = Enumerable.From({foo:10, bar:20}).ToArray(); // [{Key:"foo",Value:10}, {Key:"bar",Value:20}]

// C# - AnonymousType
array.Select((val, i) => new { Value = val, Index = i });
// linq.js - object literal
Enumerable.From(array).Select("val,i=>{Value:val, Index:i}")

jQuery plugin version

// $.Enumerable
$.Enumerable.Range(1, 10).Where("$%2==0").ForEach("alert($)");

// TojQuery - Enumerable to jQuery
$.Enumerable.Range(1, 10)
    .Select(function (i) { return $(").text(i)[0] })
    .TojQuery()
    .appendTo("#select1");

// toEnumerable - jQuery to Enumerable
var sum = $("#select1").children()
    .toEnumerable()
    .Select("parseInt($.text())")
    .Sum(); // 55

linq-jquery.jpg

IntelliSense vsdoc

linqjs_intellisense.jpg

video - using with Visual Studio 2010



video - how to debug linq.js


with Windows Script Host

// get folder name and file name...

var dir = WScript.CreateObject("Scripting.FileSystemObject").GetFolder("C:\\");
 
// normally
var itemNames = [];
for (var e = new Enumerator(dir.SubFolders); !e.atEnd(); e.moveNext())
{
    itemNames.push(e.item().Name);
}
for (var e = new Enumerator(dir.Files); !e.atEnd(); e.moveNext())
{
    itemNames.push(e.item().Name);
}

// linq.js
var itemNames2 = Enumerable.From(dir.SubFolders).Concat(dir.Files).Select("$.Name").ToArray();

SQL Subquery

SQL Subquery

Subquery or Inner query or Nested query is a query in a query. A subquery is usually added in the WHERE Clause of the sql statement. Most of the time, a subquery is used when you know how to search for a value using a SELECT statement, but do not know the exact value in the database.
Subqueries are an alternate way of returning data from multiple tables.
Subqueries can be used with the following sql statements along with the comparision operators like =, <, >, >=, <= etc.
  • SELECT
  • INSERT
  • UPDATE
  • DELETE

    Subquery Example:

    1) Usually, a subquery should return only one record, but sometimes it can also return multiple records when used with operators like IN, NOT IN in the where clause. The query would be like,
    SELECT first_name, last_name, subject 
    FROM student_details 
    WHERE games NOT IN ('Cricket', 'Football'); 
    The output would be similar to:
    first_namelast_namesubject
    ------------------------------------
    ShekarGowdaBadminton
    PriyaChandraChess
    2) Lets consider the student_details table which we have used earlier. If you know the name of the students who are studying science subject, you can get their id's by using this query below,
    SELECT id, first_name 
    FROM student_details 
    WHERE first_name IN ('Rahul', 'Stephen'); 
    but, if you do not know their names, then to get their id's you need to write the query in this manner,
    SELECT id, first_name 
    FROM student_details 
    WHERE first_name IN (SELECT first_name 
    FROM student_details 
    WHERE subject= 'Science'); 
    Output:
    idfirst_name
    ---------------------
    100Rahul
    102Stephen
    In the above sql statement, first the inner query is processed first and then the outer query is processed.

    3) Subquery can be used with INSERT statement to add rows of data from one or more tables to another table. Lets try to group all the students who study Maths in a table 'maths_group'.
    INSERT INTO maths_group(id, name) 
    SELECT id, first_name || ' ' || last_name 
    FROM student_details WHERE subject= 'Maths' 

    4) A subquery can be used in the SELECT statement as follows. Lets use the product and order_items table defined in the sql_joins section.
    select p.product_name, p.supplier_name, (select order_id from order_items where product_id = 101) as order_id from product p where p.product_id = 101
    product_namesupplier_nameorder_id
    ----------------------------------------------
    TelevisionOnida5103

    Correlated Subquery

    A query is called correlated subquery when both the inner query and the outer query are interdependent. For every row processed by the inner query, the outer query is processed as well. The inner query depends on the outer query before it can be processed.
    SELECT p.product_name FROM product p 
    WHERE p.product_id = (SELECT o.product_id FROM order_items o 
    WHERE o.product_id = p.product_id); 
    NOTE:
    1) You can nest as many queries you want but it is recommended not to nest more than 16 subqueries in oracle.
    2) If a subquery is not dependent on the outer query it is called a non-correlated subquery.

INNER JOIN UPDATE : Update Table with INNER JOIN

INNER JOIN UPDATE Often we may need to update a column in a table based of another column in another table.
In SQL Server you can do this using UPDATE statement by joining tables together.
To understand this better let’s take a look at below contrived example.
USE [SqlAndMe]
GO

SELECT CustomerID, Name, OrderAmount
FROM   dbo.Customers
GO

SELECT OrderID, CustomerID, Amount
FROM   dbo.Orders
GO
Result Set:
CustomerID    Name          OrderAmount
3             Curtis        NULL
4             Lanna         NULL
5             Marlin        NULL
6             Henry         NULL

(4 row(s) affected)

OrderID       CustomerID    Amount
107           6             8745.00
123           5             4582.00
643           3             5693.00

(3 row(s) affected)
In the above data I want to update OrderAmount column of dbo.Customers with values fromAmount column of dbo.Orders.
To achieve this we can use UPDATE statement as below:
UPDATE CUST
SET    CUST.OrderAmount = ORDR.Amount
FROM   dbo.Customers CUST
INNER JOIN dbo.Orders ORDR ON CUST.CustomerID = ORDR.CustomerID
GO

(3 row(s) affected)
OrderAmount column in dbo.Customers Table is now updated based on JOIN condition.
SELECT CustomerID, Name, OrderAmount
FROM   dbo.Customers
GO
CustomerID    Name          OrderAmount
3             Curtis        5693.00
4             Lanna         NULL
5             Marlin        4582.00
6             Henry         8745.00

(4 row(s) affected)

ภาษาไทย

ถ้าเราต้องมีการ update หรือ delete ข้อมูลในฐานข้อมูลคราวละหลาย record ด้วยเงื่อนไขบางอย่าง ถ้าเป็นไปได้ควรจะเขียนให้ทำงานได้ด้วยคำสั่ง SQL Command เดียว หากเงื่อนไขนั้นอยู่ในตารางที่ต้องการจะลบอยู่แล้ว SQL Command ก็จะตรงไปตรงมา อย่างเช่นคำสั่ง update ก็จะเป็นประมาณนี้
1
update table1 set field1=0, field2='a' where field3 is null
และการ delete
1
delete from table1 where field3 is null
แต่หากเราต้องการ update ตาราง table1 แต่ว่าเงื่อนไขเราอยู่ในตารางอื่น หรือแม้แต่ข้อมูลที่จะมา update อยู่ในตารางอื่น
ใน SQL Server เราสามารถใช้การ join เข้ามาช่วยใน sql ได้ดังนี้
1
2
3
update t1 set t1.field1=0, t1.field2=t2.field2
from table1 t1 inner join table2 t2 on t1.joinfield=t2.joinfield
where t2.field3 is null
และการ delete
1
2
3
delete from t1
from table1 t1 inner join table2 t2 on t1.joinfield=t2.joinfield
where t2.field3 is null