LDAP基本查詢語法
開始工作真的在搞一些有的沒有
而且每個客戶的做法也都不一樣 太有趣了 ="=
先前我們使用的方式是使用帳號密碼 試著登入ldap server如果能登入就是合法的使用者
今天看到某客戶(!!!!)的demo code
事先使用一個類似admin的帳號 可以取得(查詢)所有的user
再連線至LDAP比較密碼 是否相同 (很怪吧!!!)
總之 今天有用到在LDAP的查詢語法 XDD
Ref: http://technet.microsoft.com/zh-tw/library/dd159860.aspx
Ref: http://www.novell.com/documentation/developer/jldap/jldapenu/api/
2012年7月31日 星期二
SQL Server中與Metadata相關的預設table
SQL Server 2000中(之後可以改用VIEW來完成相同的工作)
有一些系統的table來儲放資料的metadata
store database-level system information for each database.
查詢某TABLE的某COLUMN存不存在
use [DB_NAME]
GO
DECLARE @tb_name VARCHAR(512), @col_name VARCHAR(512)
SET @tb_name = 'TABLE_NAME'
SET @col_name = 'COL_NAME'
IF NOT EXISTS(
SELECT 1
from sys.sysobjects so
INNER JOIN sys.syscolumns sc ON sc.id = so.id
where so.name = @tb_name AND sc.name = @col_name
)
BEGIN
PRINT 'COLUMN ''' + @col_name+ ''' is NOT EXISTS!!'
END
ELSE
BEGIN
PRINT 'COLUMN ''' + @col_name+ ''' is EXISTS!!'
END
GO
http://msdn.microsoft.com/en-us/library/aa260604(v=sql.80)
有一些系統的table來儲放資料的metadata
System Tables in Every Database
store database-level system information for each database.
syscolumns
|
Sysindexkeys
|
syscomments
|
sysmembers
|
sysconstraints
|
sysobjects
|
sysdepends
|
syspermissions
|
sysfilegroups
|
sysprotects
|
sysfiles
|
sysreferences
|
sysforeignkeys
|
systypes
|
sysfulltextcatalogs
|
sysusers
|
sysindexes
|
查詢某TABLE的某COLUMN存不存在
use [DB_NAME]
GO
DECLARE @tb_name VARCHAR(512), @col_name VARCHAR(512)
SET @tb_name = 'TABLE_NAME'
SET @col_name = 'COL_NAME'
IF NOT EXISTS(
SELECT 1
from sys.sysobjects so
INNER JOIN sys.syscolumns sc ON sc.id = so.id
where so.name = @tb_name AND sc.name = @col_name
)
BEGIN
PRINT 'COLUMN ''' + @col_name+ ''' is NOT EXISTS!!'
END
ELSE
BEGIN
PRINT 'COLUMN ''' + @col_name+ ''' is EXISTS!!'
END
GO
SQL Server中與Metadata相關的預設View
SQL Server 2005, 2008, 2008 R2, 2012
在INFORMATION_SCHEMA中有一些預設的system view可以來查詢一些跟資料庫相關的資訊
像是table名稱、column名稱等
Ref: http://msdn.microsoft.com/en-us/library/ms186778.aspx
在INFORMATION_SCHEMA中有一些預設的system view可以來查詢一些跟資料庫相關的資訊
像是table名稱、column名稱等
|
CHECK_CONSTRAINTS
|
REFERENTIAL_CONSTRAINTS
|
|
COLUMN_DOMAIN_USAGE
|
ROUTINES
|
|
COLUMN_PRIVILEGES
|
ROUTINE_COLUMNS
|
|
COLUMNS
|
SCHEMATA
|
|
CONSTRAINT_COLUMN_USAGE
|
TABLE_CONSTRAINTS
|
|
CONSTRAINT_TABLE_USAGE
|
TABLE_PRIVILEGES
|
|
DOMAIN_CONSTRAINTS
|
TABLES
|
|
DOMAINS
|
VIEW_COLUMN_USAGE
|
|
KEY_COLUMN_USAGE
|
VIEW_TABLE_USAGE
|
|
PARAMETERS
|
VIEWS
|
Ref: http://msdn.microsoft.com/en-us/library/ms186778.aspx
2012年6月12日 星期二
用一維陣列解n皇后問題
用一維陣列解n皇后問題
使用 2 維的陣列來儲存棋盤 似乎是比較直覺的做法
所以我們會在 map[n][n] 這樣的陣列裡面填上0跟1來表示皇后放在哪裡
接著檢查的方式 就是檢查 每一個行、每一個列、斜角有沒有被放上皇后
OK~ 簡單Easy~
接下來 討論一下利用一維陣列 來儲存
直接將 map[i][j] = 1 取代成 arr[i] = j
檢查的方式呢
檢查map[i][j]第 i 列的部分 由於我們填入的時候 是一列一列的填入 (依照index) 所以可以跳過了
檢查map[i][j]第 j 行的部分 就檢查目前放入陣列的數字有沒有重複就可以了
至於斜角也很簡單 原先map[i][j]與map[[k][l]是否是在斜線的關系
原先使用 |i-k| == |j-l| if (i,j ) != (j, k)來檢查
現在改用 arr[i] = j 與 arr[k] = l 就會變成 |i - k| == |arr[i] - arr[k]| if (i,j ) != (j, k)
import java.util.Arrays;
import java.util.Scanner;
public class JAVA {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = 0 ;
while (cin.hasNext()) {
n = cin.nextInt();
if(n > 0)
printQueen(n);
else break ;
}
}
static void printQueen(int n){
int count = 0 ;
int map[] = new int[n];
int level = 0;
Arrays.fill(map, -1);
for(int i = 0 ; i < n ; i++){
map[i] = level;
count += dfs(n, i, level, map);
map[i] = -1 ;
}
System.out.println(count);
System.out.println();
}
// map[i] = j -->> map[i][j] -> checked
// map[i][j], map[k][l] are conflicted >>> |i-k| == |j-l|
private static int dfs(int n, int i, int level, int[] map) {
if(level == n-1){
printQueenMap(n, map);
return 1 ;
}else{
int count = 0;
for(int k = 0 ; k < n ; k++){
if(map[k] != -1) continue;
boolean flag = true;
for(int ii = 0 ; flag && ii < n ;ii++){
if(map[ii] != -1)
if(Math.abs(ii-k) == Math.abs(map[ii]-level-1)){
flag = false ;
}
}
if(flag){
map[k] = level+1;
count += dfs(n,k,level+1, map);
map[k] = -1;
}
}
return count;
}
}
private static void printQueenMap(int n, int[] map) {
for(int x = 0 ; x < n ; x++){
int tmp = -1;
for(int y = 0; y < n ; y++){
if(map[y] == x){
tmp = y ;
break;
}
}
String XX = repeat("x",n);
System.out.print(XX.substring(n-tmp));
System.out.print("Q");
System.out.println(XX.substring(tmp+1));
}
System.out.println();
}
public static String repeat(String s, int times) {
if (times <= 0) return "";
else return s + repeat(s, times-1);
}
}
2012年3月4日 星期日
Closures
JavaScript - Closures are means through which inner functions can refer to the variables present in their outer enclosing function after their parent functions have already terminated.
2012年2月10日 星期五
歷史紀錄
原始資料表
歷史資料表 << 原始資料表
+ 更新序號
+ 更新時間
+ 更新方式 (A, U, D)
(+ 更新人)
(+ 更新原因)
trigger
新增
insert into 原始資料表
修改
update 原始資料表
刪除
delete from 原始資料表
------------------
歷史資料表只能新增 再 藉由trigger對 原始資料表作更動
由於所以無法指藉由資料來顯示是新增或是刪除
所以需要一個變更方式的欄位
------------------ update @ 2012/2/10 05:43
java 可以建立一個歷史紀錄的類別(介面)
public interface HistoricalData{
void setUpdateSeq(int updateSeq);
int getUpdateSeq();
void setUpdateDatetime(Date datetime);
Date getUpdateDatetime();
void setUpdateType(String updateType);
String getUpdateType();
}
------------------ update @ 2012/2/10 05:43
java 可以建立一個歷史紀錄的類別(介面)
public interface HistoricalData{
void setUpdateSeq(int updateSeq);
int getUpdateSeq();
void setUpdateDatetime(Date datetime);
Date getUpdateDatetime();
void setUpdateType(String updateType);
String getUpdateType();
}
2011年12月15日 星期四
libraries
Spring framework將Java的Reflection做了很厲害的包裝
用來完成IoC和DI
IoC : Inversion of Control
DI : Dependency Injection
Struts2 來自 WebWork2 Framework是用來建立Java web application的framework
struts2-spring : Spring與Struts2可以透過 struts2-spring-plugin 來連接 在Struts2中使用Spring
Apache commons dbcp - Database Connection Pooling
http://commons.apache.org/dbcp/
包裝了常用的連接資料庫用的功能
dbcp依賴 jakarta commons-pool
Json-lib能將beans, maps, collections, java arrays, XML等轉成JSON物件 與 把它反轉成 beans and DynaBeans
依賴
用來完成IoC和DI
IoC : Inversion of Control
DI : Dependency Injection
Struts2 來自 WebWork2 Framework是用來建立Java web application的framework
struts2-spring : Spring與Struts2可以透過 struts2-spring-plugin 來連接 在Struts2中使用Spring
Apache commons dbcp - Database Connection Pooling
http://commons.apache.org/dbcp/
包裝了常用的連接資料庫用的功能
dbcp依賴 jakarta commons-pool
Json-lib能將beans, maps, collections, java arrays, XML等轉成JSON物件 與 把它反轉成 beans and DynaBeans
依賴
- jakarta commons-lang 2.5
- jakarta commons-beanutils 1.8.0
- jakarta commons-collections 3.2.1
- jakarta commons-logging 1.1.1
- ezmorph 1.0.6
2011年10月13日 星期四
JDBC String 的參數列表
JDBC String 的參數列表
用到 zeroDateTimeBehavior 所以找到這個東東
因為資料庫填的日期是0000-00-00沒有辦法給Java 的Date類別轉換
這個參數有三種值 exception, round, convertToNull分別是丟出例外, 轉換成0000-01-01, 回傳null三種
What should happen when the driver encounters DATETIME values that are composed entirely of zeros (used by MySQL to represent invalid dates)? Valid values are "exception", "round" and "convertToNull".
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
用到 zeroDateTimeBehavior 所以找到這個東東
因為資料庫填的日期是0000-00-00沒有辦法給Java 的Date類別轉換
這個參數有三種值 exception, round, convertToNull分別是丟出例外, 轉換成0000-01-01, 回傳null三種
What should happen when the driver encounters DATETIME values that are composed entirely of zeros (used by MySQL to represent invalid dates)? Valid values are "exception", "round" and "convertToNull".
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
2011年5月20日 星期五
真值表
| A | B | 0 | A&~B | A&B | ~(A|B) | ~A&B | A | A^~B | ~A | A^B | ~B | B | A|~B | ~A|B | ~(A&B) | A|B | 1 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
這個是所有的真假值的排列組合
2011年2月4日 星期五
Windows Command Line
dir usage
- dir /b *.java
- list all files end with .java in current directory in simple format
- dir /b/s *.java
- list all files end with .java in current directory recursively in simple format
for usage
- for [/d][/r] %i in (set) do command [command-parameters]
- %i : variable, case sensitive
- set : file list. ex : (file.txt file2.txt), (*.txt)
- /d : similar to 1. but (set) is not file list, is a directory list
- /r : do same "for work" in every sub directory of current place
- for /L %variable in (start,step,end) do command [command-parameters]
- numerical iteration. ex. (1,1,5) = (1 2 3 4 5), (5,-1,1) = (5 4 3 2 1)
- FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
- FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
- FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
- FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
- FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
- FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]
- eol=c : end of line charactor
- skip=n : skip n lines
- delims=xxx : delims charactor list
- tokens=x,y,m-n :
- 指定每一行的哪些文字串應該被傳到 for 的內部以用來進行每一個重複操作。
- 這會導致額外的變數名稱被配置。
- m-n 格式代表一個範圍,指定了第 m 個到第 n 個字串項。
- 如果在 tokens= 字串的最後一個字元是星號,則會配置一個額外的變數來接收最後一個字串項被分析後的其他文字。
- usebackq
- 指定新語義開始作用。
- `反括號`的字串會被當作命令來執行
- '單引號'字串是純文字字串
- 此外還允許使用"雙引號"來引用在 filenameset 內的檔名。
example :
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
%IMPORTENT%
when using a variable in batch file, the usage is %%v not %v
訂閱:
意見 (Atom)