2009年6月28日 星期日

如何在Windows上建置mobile device的模擬環境

由於瀏覽器的支援度與螢幕的大小等問題, 常常我們以電腦上的瀏覽器和以行動裝置上的瀏覽器觀看網站, 所看到的結果會有所不同, 因此我們會需要另外建置一適合行動裝置所瀏覽的網站, 這時就需要建置行動裝置的模擬環境了...

建置Windows Mobile 6與設定網路共用
Download and install Microsoft ActiveSync
Download and install the Microsoft Device Emulator 3
Download and install the Windows Mobile 6 Professional Images
Start -> Programs -> Windows Mobile 6 SDK -> Tools -> Device Emulator Manager->Right Click the Entry and select "Cradle"
In ActiveSync panel, check the Allow connections to one of the following box, then select DMA from the dropdown list and click OK
相關圖文可參考這篇


建置Android
Download and install Android SDK
Download and install Eclipse(若只需使用Android的瀏覽器則不需安裝)
相關圖文可參考這篇

2009年6月9日 星期二

Split Function in SQL Server 2005

有鑒於事情應該正常分工的政策下(其實是覺得資料庫使用率偏低@@), 在有欄位需要以類似split的函式取出所要的部份需求, 撰寫一函式與相關的SQL語法如下:

1. SQL Server 2005->Object Explorer->Databases->New Query
2. Create split function
IF OBJECT_ID (N'dbo.split', N'IF') IS NOT NULL
DROP FUNCTION dbo.split
GO

CREATE FUNCTION dbo.split(@String VARCHAR(8000), @Delimiter CHAR(1))
RETURNS @temptable TABLE (items VARCHAR(8000))
AS
BEGIN
DECLARE @idx INT
DECLARE @slice VARCHAR(8000)

SELECT @idx = 1
IF LEN(@String)<1 idx =" CHARINDEX(@Delimiter,@String)" slice =" LEFT(@String,@idx" slice =" @String">0)
INSERT INTO @temptable(Items) VALUES(@slice)

SET @String = RIGHT(@String,len(@String) - @idx)
IF LEN(@String) = 0 BREAK
END
RETURN
3. Using nested queries with split function
SELECT DISTINCT FIELD1_NAME FROM TABLE1_NAME WHERE FIELD2_NAME = (
SELECT TOP (1) items FROM
dbo.split(
(SELECT FIELD3_NAME
FROM TABLE2_NAME
WHERE (FIELD4_NAME = 'FIELD4_VALUE')), ':')
)

參考Split Function in Sql Server

2009年6月8日 星期一

FreeTDS的加密傳輸(Secure Connection)

最近遇到的鐵板是使用FreeTDS連接SQL Server會出現模稜兩可的Msg 20017錯誤訊息,
Msg 20017, Level 9, State -1, Server OpenClient, Line -1
Unexpected EOF from the server

使用TDSDUMP看錯誤訊息後發現在傳輸建立初期就已經被中斷,
util.c:334:tdserror(0x997e0a8, 0x997ea50, 20017, 0)
util.c:368:tdserror: client library returned TDS_INT_CANCEL(2)

在來回比對之後才發現遇到了有加密(Force Encryption)的SQL Serve,

需以--with-openssl=/src/openssl --with-gnutls的設定重新安裝FreeTDS, 並且在FreeTDS的設定檔中加上 encryption = required或request的參數,

看似美好, 但重新安裝後仍遇到一樣的錯誤訊息, 再度以TDSDUMP檢查後發現訊息有所不同了, 是在送出表頭前出錯的...
net.c:779:Sending packet
0000 12 01 00 34 00 00 00 00-00 00 15 00 06 01 00 1b |...4.... ........|
0010 00 01 02 00 1c 00 0c 03-00 28 00 04 ff 08 00 01 |........ .(......|
0020 55 00 00 00 4d 53 53 51-4c 53 65 72 76 65 72 00 |U...MSSQ LServer.|
0030 f2 31 00 00 - |.1..|

原來因為一開始安裝機器時不想裝進一些亂七八糟的東西, 所以只選了確定要的套件, 因此少裝了某些加密模組, 最後還是只好拿出光碟片乖乖的把base的東西補齊,

終於可以快快樂樂的以FreeTDS進行加密傳輸了...

2009年5月19日 星期二

在Linux環境下以PHP連結SQL Server

若在Windows環境下安裝PHP, 通常可以很輕鬆的連結SQL Server, 但在Linux環境下就需要額外安裝FreeTDS, 詳細安裝步驟可以參考這篇這篇, 我也順便再記錄一次操作步驟吧...

1) 安裝FreeTDS:
  • 先下載FreeTDS的source,
  • 編譯參數: --prefix=/usr/local/freetds --enable-msdblib
  • 完成安裝後, 修改/etc/ld.so.conf, 加入/usr/local/freetds/lib; 以ldconfig重新載入函式
2) 修改/usr/local/freetds/etc/freetds.conf:
[foo]
host = your.mssql.server.ip
port = 1433
client charset = UTF-8 # 以UTF-8編碼方式連線
tds version = 8.0
#tds version: 4.2 (適用 MS SQL Server 6.x); 7.0 (適用 7.x); 8.0 (適用 2000/2005)
3) 測試連線
  • # /usr/local/freetds/bin/tsql -S foo -U sa
  • 1> use my_db
  • 2> select * from my_table
  • 3> go
4) 重新編譯PHP
  • 新增編譯參數: --with-mssql=/usr/local/freetds

在存取SQL Server 2005時, 若遇到欄位型態為uniqueidentifier, PHP無法直接取得其欄位值, 需在SQL查詢以SELECT CONVERT(VARCHAR(36), field_name) AS 'field_name'轉換型態才可使用, 而要新增uniqueidentifier類型的欄位時, 須以SQL Server內建之NewID()函式產生唯一的GUID

2009年5月12日 星期二

在Linux環境安裝Subversion

最近由於工作需要, 必須在Linux下安裝版本控制系統, 經過比較之後, 雖然Subversion(SVN)在commit的速度不如Git, 而且branch的管理也較差, 但用順手後也就習慣了, 在此紀錄一下安裝過程...
在Linux環境下先抓取Apache和SVN的source後編譯, 由於習慣使用webdav的方式透過http更新, 因此在Apache編譯前要先設定
# ./configure --enable-dav --enable-so --enable-maintainer-mode

根據Apache2.0x的預設安裝路徑, 繼續SVN的編譯
# ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-apr=/usr/local/apr/bin/

在安裝SVN的過程中有時會出現'configure: error: Subversion requires SQLite'的錯誤訊息, 這時就須先下載sqlite-amalgamation, 解開壓縮檔後將sqlite3.c複製到subversion-x.x.x/sqlite-amalgamation的目錄下再行安裝,

安裝完成後開始建立Repository, 注意不要建立在web server文件下的目錄,
# svnadmin create /var/svn

有時也會遇到'txn-current-lock': Permission denied的問題, 就必須修改權限給Apache的使用群組(可見httpd.conf)
# chown -R daemon:daemon /var/svn

修改httpd.conf設定,
# vim /usr/local/apache2/conf/httpd.conf
[add]
<location /myprj>
Dav svn
SVNPath /var/svn/myprj
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /usr/local/apache2/conf/auth-file
Require valid-user
<//Location>
[/add]

加上Apache基本認證
# /usr/local/apache2/bin/htpasswd -c /usr/local/apache2/conf/auth-file USERNAME

確認是否成功, 重新啟動Apache
# /usr/local/apache2/bin/apachectl restart

開啟瀏覽器輸入以下網址
http://127.0.0.1/myprj

如果在登入帳號密碼後看到下列訊息, 表示成功安裝以webdav存取的的svn server
myprj - Revision 0: /

進一步的設定可參考Subversion系統, Subversion FAQVersion Control with Subversion, 而在Window環境下安裝可參考這裡

2009年3月20日 星期五

The Difference Between include() and require() in PHP

When the handle are failed,
include() will produce a Warning and the script will continue regardless.
require() results in a Fatal Error and halts the script.

2009年2月28日 星期六

Install VMware Tools on Linux

# yum install gcc kernel-headers kernel-devel

How to fix the problem when "What is the location of the directory of C header files that match your running kernel" error occurred?

The location of the directory of C header files is: /usr/src/kernels/`uname -r`/include/

If the error message was like
The directory of kernel headers (version @@VMWARE@@ UTS_RELEASE) does not match your running kernel...

The vmware-config-tools.pl is looking for define UTS_RELEASE within either version.sh or utsrelease.h under ./linux/ Unfortunately it wasn't there yet.
# cd /usr/src/kernels/`uname -r`/include
# cp -p generated/utsrelease.h linux/utsrelease.h

In the environment of VMWare Workstation 6.5.4 with Linux kernel 2.6.33.*, there is somehow difficult... If the "Virtual Network Device" was compiled failed in "Vmware Kernel Module Updater", the steps below were worked for me.
cd /usr/src/kernels/`uname -r`/include/linux/
# ln -sf ../generated/autoconf.h .
# ln -sf ../generated/utsrelease.h .
# tar xf /usr/lib/vmware/modules/source/vmnet.tar
# cd vmnet-only
In vnetUserListener,c, add the line:
#include
after
#include "vnetInt.h"
# cd ..
# tar cf vmnet.tar vmnet-only
# mv vmnet.tar /usr/lib/vmware/modules/source/
# tar xf /usr/lib/vmware/modules/source/vmci.tar
# cd vmci-only/include
In pgtbl.h, add the line:
#include
after
#include "compat_page.h"
# cd ../..
# tar cf vmci.tar vmci-only
# mv vmci.tar /usr/lib/vmware/modules/source/

reference:
VMWare Workstation 6.5.4 with Linux kernel 2.6.33.4
VMware Tools on 64-bit Ubuntu 9.10
圖文並茂,VMware 6.5.1for linux下載安裝、註冊機、VM tools及虛擬系統應用安裝教程