2013年7月22日 星期一

[sql server] 列出 database 內所有 table



select * from sys.tables

[sql server]列出 engine 內所有 database

ref : http://msdn.microsoft.com/en-us/library/ms188613.aspx

select * from sys.databases

[sql server]取得目前所在資料庫名稱

ref : http://blog.sqlauthority.com/2008/02/12/sql-server-get-current-database-name/

SELECT DB_NAME()

2013年7月16日 星期二

[SQL server] 字串前的 'N'

code like this :

SELECT *
FROM tableA
WHERE columnA
LIKE N'%文字%'


表示後面接的字串是 unicode 的文字

2013年7月15日 星期一

[C#] using() 的意義

-----------------------------------------------------------
ref : http://msdn.microsoft.com/zh-tw/library/yh598w02.aspx
-----------------------------------------------------------

在 using() 宣告並初始化的物件, 在離開 using(){} 前會自動 Dispose() .
記憶體管理用


using (Font font1 = new Font("Arial", 10.0f)) 
{
     byte charset = font1.GdiCharSet;
}


也就是說, 以上這段 code, 實際上會有以下這段的功能

{
Font font1 = new Font("Arial", 10.0f);
try
     {
          byte charset = font1.GdiCharSet;
     }
     finally
     {
          if (font1 != null)
         ((IDisposable)font1).Dispose();
     }
}

[C#] @的用法


------------------------------------
ref : http://note.tc.edu.tw/209.html
------------------------------------

@之後的字串會把 \ 當成一般字元處理

sample 1 :

c:\program files\

string d = "c:\\program files\\"
string e = @"c:\program files\"


sample 2 : 要使用特殊字的話

"c:\program files\"

string f = "\"c:\\program files\\\""
string e = @""c:\program files\""

2013年3月30日 星期六

[objective C] 定時重複執行 NSTimer


NSTimer 可以設定倒數時間, 時間到了就去把指定的方法叫起來跑,
例如說我要每 0.5 秒換一次背景顏色, 就要先定義好

1) 換顏色的方法 - (void) changeBgColorOfRootView:(NSTimer *)sender,
2) 生出一個 0.5 秒後會觸發的 NSTimer 出來,

使用的方法如下:

viewController.m : 

- (void) changeBgColorOfRootView:(NSTimer*)sender
{
    [self.view setBackgroundColor:
                          [UIColor colorWithRed: (float)rand()/RAND_MAX 
                                                    green:(float)rand()/RAND_MAX 
                                                      blue:(float)rand()/RAND_MAX 
                                                    alpha:(float)rand()/RAND_MAX ]] ;


- (void)viewDidLoad
{
 ...

    [NSTimer 
       scheduledTimerWithTimeInterval:0.5 
       target:self 
       selector:@selector(changeBgColorOfRootView:) 
       userInfo:nil 
       repeats:YES];
    
 ...    
    
}



相關說明
-----------------------------------------------------
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval) seconds
target:(id)target
selector:(SEL)aSelector
userInfo:(id)userInfo
repeats:(BOOL)repeats


Description
Creates and returns a new NSTimer object and schedules it on the current run loop in the default mode. After seconds seconds have elapsed, the timer fires, sending the message aSelector to target.


Parameters

secondsThe number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.


target
The object to which to send the message specified by aSelector when the timer fires. The target object is retained by the timer and released when the timer is invalidated.


aSelector
The message to send to target when the timer fires. The selector must correspond to a method that returns void and takes a single argument. The timer passes itself as the argument to this method.


userInfoThe user info for the timer. The object you specify is retained by the timer and released when the timer is invalidated. This parameter may be nil.


repeats
If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires. Returns A new NSTimer object, configured according to the specified parameters. Availability iOS (2.0 and later)


Declared NSTimer.h Reference

2013年3月27日 星期三

[objective C] .m 裡面的 @interface

ref : http://stackoverflow.com/questions/3967187/difference-between-interface-definition-in-h-and-m-file#_=_


一般來說, 在 objective C 宣告和實作應該會分別存放在 .h 和 .m 檔中,
然後用 @interface ... @end 和 @implementation ...@end 標開來,

但是有時候 @interface 也會出現在 .m 中 , 像這樣


Person.h:
@interface Person
{
    NSString *_name;
}

@property(readwrite, copy) NSString *name;
-(NSString*)makeSmallTalkWith:(Person*)person;
@end




Person.m:
@interface Person () //Not specifying a name for the category makes compiler checks that these methods are implemented.

-(void)startThinkOfWhatToHaveForDinner;
@end


@implementation Person

@synthesize name = _name;

-(NSString*)makeSmallTalkWith:(Person*)person
{
    [self startThinkOfWhatToHaveForDinner];
    return @"How's your day?";
}


-(void)startThinkOfWhatToHaveForDinner
{

}

@end


文中的解釋是說. 在 .m 檔的 @interface 中的宣告叫做 "class extension"(類別延伸?), 自動會變成 private ,







more info : http://macdevelopertips.com/objective-c/objective-c-categories.html