PageRank



轉移公告

計劃把 http://blog.hoamon.info/ 文章全部轉移至 http://www.hoamon.info/blog/ 這裡,而本 Blogger 站台的文章近 500 篇,我預計在 2014-12-31 前移轉完畢,完成後 http://blog.hoamon.info/ 將只作代轉服務,一律把舊連結如 http://blog.hoamon.info/index.html 轉成 http://www.hoamon.info/blog/index.html ,敬請舊雨新知互相走告。

新文章只發佈在 http://www.hoamon.info/blog/ 。

何岳峰 敬上
顯示具有 microsoft 標籤的文章。 顯示所有文章
顯示具有 microsoft 標籤的文章。 顯示所有文章

2008年3月24日 星期一

How to connect MS SQL Server with Python in the Linux OS?

Basically, the general method is using ODBC Interface. In the Unix environment, we can use unixODBC library, but i had tried in failure.

So... another method is using hard core TDS protocol of Sybase Server. because MicroSoft buy the MSSQL server source code from Sybase, so they use the same protocol. maybe there are some difference between the servers. but i could not found it as far.

and i wanted using Python to program, so the requirement is below here:
  • freetds(http://www.freetds.org/): TDS protocol library written in C
  • python-sybase(http://www.freetds.org/userguide/python.htm): python interface for controll freetds library
  • python-devel (using in compile python-sybase)
Installation in Ubuntu is so easy, try apt-get install python-devel first. and then install freetds and python-sybase. command is below here:

# tar -zxf freetds.tgz

# cd freetds

# ./configure --prefix=/usr/local/freetds

# make

# sudo make install

# tar -zxf python-sybase.0.37.tgz #PS i try 0.37, because 0.38 is having something wrong in my server

# cd python-sybase.0.37

# sudo SYBASE=/usr/local/freetds \
CFLAGS="-DHAVE_FREETDS" \
LD_LIBRARY_PATH=/usr/local/freetds/lib:${LD_LIBRARY_PATH} \
python setup.py install


OK! installation is done!

try the freetds library is OK!

# /usr/local/freetds/bin/tsql -H {ServerIP} -p 1433 -U {Username} -P {Password}

> EXEC sp_databases

> go

this 『EXEC sp_databases』 command will show the all databases that this {Username} can read.

> use testdb

> EXEC sp_tables

> go

this 『EXEC sp_tables』 command will show the all tables of testdb.

> EXEC sp_columns @table_name = 'users'

> go

this 『EXEC sp_columns @table_name = 'users'』 command will show the all fields of table 'users'.

if everything seen OK! you can try Sybase module in the python interpreter.

# SYBASE=/usr/local/freetds CFLAGS="-DHAVE_FREETDS" LD_LIBRARY_PATH=/usr/local/freetds/lib /usr/bin/python
 1 import Sybase

2 class DictCursor(Sybase.Cursor):

3 def row2dict(self, row):

4 d = {}

5 for i,elt in enumerate(row):

6 d[self.description[i][0]] = elt

7 return d

8 def fetchall(self):

9 rows = Sybase.Cursor.fetchall(self)

10 result = []

11 for row in rows:

12 result.append(self.row2dict(row))

13 return result

14 def fetchone(self):

15 return row2dict(Sybase.Cursor.fetchone(self))

16 def fetchmany(self):

17 rows = Sybase.Cursor.fetchmany(self)

18 result = []

19 for row in rows:

20 result.append(self.row2dict(row))

21 return result

22 class Connection(Sybase.Connection):

23 def dictcursor(self):

24 return DictCursor(self)

25 db = Connection(ip:port, account, password, dbname)

26 c = db.dictcursor()

27 sql = "select * from sometable"

28 c.execute(sql)

29 rows = c.fetchall()

30 for row in rows:

31 for k, v in row.items():

32 print k, v

33 print 'done'
OK! this is real done!

2008年2月8日 星期五

我看MicroSoft 併購 Yahoo!

我十分希望 MS 能真的買下 Yahoo! ,但應該還要讓 MS 再多花點錢來買,或許等 Yahoo! 把廣告業務批給 Google 後,再賣給 MS 會更好。

理由如下:
  1. 網路世界留下兩強即可
  2. 我不喜歡 MS 和 Yahoo!
  3. MS 會失去世界第一的光采

第一點: 就像民主黨與共和黨一樣,兩元化的世界比較簡單。就像 Un*x 與 Windows 一樣,你爭我奪就夠,如果還有個「他」來湊一腳,會比較礙眼。

第二點: MS 就不提了, Yahoo! 令我討厭的原因,就在於它的購物平台沒 PChome 方便, Email 服務技術不如 Google ,雖然我用了 YUI 函式庫,不過,目前也想換成 Jquery 了。總之, Yahoo! 技術沒一項獨強,該被淘汰吧!兩者放在一起,我就只須要討厭一個就行,「小小」併購就讓我心頭上少一塊贅肉,令人大快。

第三點: MS 併下 Yahoo! 後,必然有陣痛期,兩家公司員工本來就不是同流的,且你看看,會有多少台 FreeBSD 會被換成 Windows 2003 Server 呢! 想到這點,我就開心, MS 的工程人員必須花相當大的內耗才能把兩家公司的炮火集中,而在這之前, Google 不知道又可以跑多少了。就算 N 年後, MS 併 Yahoo! 的效益浮現,但我可預期的是,在浮現之前, Google 已能奪下資訊服務的寶座。

延伸閱讀:
下面這篇文章則是以 MS 的角度來看的,它也是認為 MS 併下 Yahoo! ,其實是對 MS 不利的。
http://www.zdnet.com.tw/news/software/0,2000085678,20127763,00.htm?feed=RSS:+ZDNet+Taiwan%3A+%B7s%BBD+-+%B3%CC%AA%F1%A4C%A4%D1

2007年2月27日 星期二

有趣的Google Adwords,微軟也有在用喔~

某個機緣發現了 Google Adsense(註1) ,覺得 Google 真是一家良心企業,他們願意提供部份利潤給網頁出版者。

一般來說,網頁出版者寫網頁的心態大部份只是分享自己的成果,如果要讓這個成果有「利」可圖,得再花費一段力氣,如出書、建物流體系…等。但 Google Adsense 卻讓出版者簡單即能獲得利益,只要網頁使用者瀏覽網頁之際也點選了 Google Adsense 提供的廣告,那麼 Google 就會拿出一部份他在這個廣告所獲得利潤給網頁出版者。

談到這,請熱心的讀者不要為了「讓我多賺點錢」去點選 Google Adsense 的廣告。原因有二:
  1. 申請 Google Adsense 時,有條款禁止網頁出版者鼓勵瀏覽者點選 Google Adsense 廣告。
  2. 這樣會破壞網頁內容與廣告之間的關係。
第2條的含義在於:如果是瀏覽者是在瀏覽網頁時,恰好看到廣告內容符合需要才點選的話,對 Google 而言,還能作網頁內容與廣告之間的關連分析。像是,讀者在閱讀我所寫的 Python 文章時,發現廣告中有介紹 Python IDE 工具,並點選進入,這會讓 Google 認知到我文章中的關鍵字句與 Python IDE 是有一層關係的。

不過網頁出版者對 Google Adsense 還是不要抱持著太大的希望,想因此致富,因為瀏覽者要點選4萬~6萬次關鍵字廣告, Google 才會發給你一張50美元的支票。要把這張支票當作是一種鼓勵,而不是生活費用的依據。

像 Google Adsense 這樣的好工具,微軟也知道了,附圖是我的網站快照,可以知道微軟用 Google Adwords(註2) 來作廣告。

註1 Adsense 是網頁出版者放置廣告的系統。
註2 Adwords 是廣告主付錢給 Google ,讓他們的廣告能出現在網頁出版者的 Adsense 系統上。
Related Posts Plugin for WordPress, Blogger...