• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            網絡服務器軟件開發/中間件開發,關注ACE/ICE/boost

            C++博客 首頁 新隨筆 聯系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks

            #

            MySQL服務維護筆記


            內容摘要:使用MySQL服務的一些經驗,主要從以下幾個方面考慮的MySQL服務規劃設計。對于高負載站點來說PHP和MySQL運行在一起(或者說任何應用和數據庫運行在一起的規劃)都是性能最大的瓶頸,這樣的設計有如讓人一手畫圓一手畫方,這樣2個人的工作效率肯定不如讓一個人專門畫圓一個人專門畫方效率高,讓應用和數據庫都跑在一臺高性能服務器上說不定還不如跑在2臺普通服務器上快。

            以下就是針對MySQL作為專門的數據庫服務器的優化建議:

            1. MySQL服務的安裝/配置的通用性;
            2. 系統的升級和數據遷移方便性;
            3. 備份和系統快速恢復;
            4. 數據庫應用的設計要點;
            5. 一次應用優化實戰;

            MySQL服務器的規劃
            =================
            為了以后維護,升級備份的方便和數據的安全性,最好將MySQL程序文件和數據分別安裝在“不同的硬件”上。

                     /   / 
            | /usr <== 操作系統
            | /home/mysql <== mysql主目錄,為了方便升級,這只是一個最新版本目錄的鏈接
            硬盤1==>| /home/mysql-3.23.54/ <== 最新版本的mysql /home/mysql鏈接到這里
            \ /home/mysql-old/ <== 以前運行的舊版本的mysql

            / /data/app_1/ <== 應用數據和啟動腳本等
            硬盤2==>| /data/app_2/
            \ /data/app_3/

            MySQL服務的安裝和服務的啟動:
            MySQL一般使用當前STABLE的版本:
            盡量不使用--with-charset=選項,我感覺with-charset只在按字母排序的時候才有用,這些選項會對數據的遷移帶來很多麻煩。
            盡量不使用innodb,innodb主要用于需要外鍵,事務等企業級支持,代價是速度比MYISAM有數量級的下降。
            ./configure --prefix=/home/mysql --without-innodb
            make
            make install

            服務的啟動和停止
            ================
            1 復制缺省的mysql/var/mysql到 /data/app_1/目錄下,
            2 MySQLD的啟動腳本:start_mysql.sh
            #!/bin/sh
            rundir=`dirname "$0"`
            echo "$rundir"
            /home/mysql/bin/safe_mysqld --user=mysql --pid-file="$rundir"/mysql.pid --datadir="$rundir"/var "$@"\
            -O max_connections=500 -O wait_timeout=600 -O key_buffer=32M --port=3402 --socket="$rundir"/mysql.sock &

            注釋:
            --pid-file="$rundir"/mysql.pid --socket="$rundir"/mysql.sock --datadir="$rundir"/var
            目的都是將相應數據和應用臨時文件放在一起;
            -O 后面一般是服務器啟動全局變量優化參數,有時候需要根據具體應用調整;
            --port: 不同的應用使用PORT參數分布到不同的服務上去,一個服務可以提供的連接數一般是MySQL服務的主要瓶頸;

            修改不同的服務到不同的端口后,在rc.local文件中加入:
            /data/app_1/start_mysql.sh
            /data/app_2/start_mysql.sh
            /data/app_3/start_mysql.sh
            注意:必須寫全路徑

            3 MySQLD的停止腳本:stop_mysql.sh
            #!/bin/sh
            rundir=`dirname "$0"`
            echo "$rundir"
            /home/mysql/bin/mysqladmin -u mysql -S"$rundir"/mysql.sock shutdown

            使用這個腳本的好處在于:
            1 多個服務啟動:對于不同服務只需要修改腳本中的--port[=端口號]參數。單個目錄下的數據和服務腳本都是可以獨立打包的。
            2 所有服務相應文件都位于/data/app_1/目錄下:比如:mysql.pid mysql.sock,當一臺服務器上啟動多個服務時,多個服務不會互相影響。但都放到缺省的/tmp/下則有可能被其他應用誤刪。
            3 當硬盤1出問題以后,直接將硬盤2放到一臺裝好MySQL的服務器上就可以立刻恢復服務(如果放到my.cnf里則還需要備份相應的配置文件)。

            服務啟動后/data/app_1/下相應的文件和目錄分布如下:
            /data/app_1/
                start_mysql.sh 服務啟動腳本
                stop_mysql.sh 服務停止腳本
                mysql.pid 服務的進程ID
                mysql.sock 服務的SOCK
                var/ 數據區
                   mysql/ 用戶庫
                   app_1_db_1/ 應用庫
                   app_1_db_2/
            ...
            /data/app_2/
            ...

            查看所有的應用進程ID:
            cat /data/*/mysql.pid

            查看所有數據庫的錯誤日志:
            cat /data/*/var/*.err

            個人建議:MySQL的主要瓶頸在PORT的連接數上,因此,將表結構優化好以后,相應單個MySQL服務的CPU占用仍然在10%以上,就要考慮將服務拆分到多個PORT上運行了。

            服務的備份
            ==========
            盡量使用MySQL DUMP而不是直接備份數據文件,以下是一個按weekday將數據輪循備份的腳本:備份的間隔和周期可以根據備份的需求確定
            /home/mysql/bin/mysqldump -S/data/app_1/mysql.sock -umysql db_name | gzip -f>/path/to/backup/db_name.`date +%w`.dump.gz
            因此寫在CRONTAB中一般是:
            15 4 * * * /home/mysql/bin/mysqldump -S/data/app_1/mysql.sock -umysql db_name | gzip -f>/path/to/backup/db_name.`date +\%w`.dump.gz
            注意:
            1 在crontab中'%'需要轉義成'\%'
            2 根據日志統計,應用負載最低的時候一般是在早上4-6點

            先備份在本地然后傳到遠程的備份服務器上,或者直接建立一個數據庫備份帳號,直接在遠程的服務器上備份,遠程備份只需要將以上腳本中的-S /path/to/msyql.sock改成-h IP.ADDRESS即可。

            數據的恢復和系統的升級
            ======================
            日常維護和數據遷移:在數據盤沒有被破壞的情況下
            硬盤一般是系統中壽命最低的硬件。而系統(包括操作系統和MySQL應用)的升級和硬件升級,都會遇到數據遷移的問題。
            只要數據不變,先裝好服務器,然后直接將數據盤(硬盤2)安裝上,只需要將啟動腳本重新加入到rc.local文件中,系統就算是很好的恢復了。

            災難恢復:數據庫數據本身被破壞的情況下
            確定破壞的時間點,然后從備份數據中恢復。

            應用的設計要點
            ==============
            如果MySQL應用占用的CPU超過10%就應該考慮優化了。

            1. 如果這個服務可以被其他非數據庫應用代替(比如很多基于數據庫的計數器完全可以用WEB日志統計代替)最好將其禁用:
              非用數據庫不可嗎?雖然數據庫的確可以簡化很多應用的結構設計,但本身也是一個系統資源消耗比較大的應用。在某些情況下文本,DBM比數據庫是更好的選擇,比如:很多應用如果沒有很高的實時統計需求的話,完全可以先記錄到文件日志中,定期的導入到數據庫中做后續統計分析。如果還是需要記錄簡單的2維鍵-值對應結構的話可以使用類似于DBM的HEAP類型表。因為HEAP表全部在內存中存取,效率非常高,但服務器突然斷電時有可能出現數據丟失,所以非常適合存儲在線用戶信息,日志等臨時數據。即使需要使用數據庫的,應用如果沒有太復雜的數據完整性需求的化,完全可以不使用那些支持外鍵的商業數據庫,比如MySQL。只有非常需要完整的商業邏輯和事務完整性的時候才需要Oracle這樣的大型數據庫。對于高負載應用來說完全可以把日志文件,DBM,MySQL等輕量級方式做前端數據采集格式,然后用Oracle MSSQL DB2 Sybase等做數據庫倉庫以完成復雜的數據庫挖掘分析工作。
              有朋友和我說用標準的MyISAM表代替了InnoDB表以后,數據庫性能提高了20倍。

            2. 數據庫服務的主要瓶頸:單個服務的連接數
              對于一個應用來說,如果數據庫表結構的設計能夠按照數據庫原理的范式來設計的話,并且已經使用了最新版本的MySQL,并且按照比較優化的方式運行了,那么最后的主要瓶頸一般在于單個服務的連接數,即使一個數據庫可以支持并發500個連接,最好也不要把應用用到這個地步,因為并發連接數過多數據庫服務本身用于調度的線程的開銷也會非常大了。所以如果應用允許的話:讓一臺機器多跑幾個MySQL服務分擔。將服務均衡的規劃到多個MySQL服務端口上:比如app_1 ==> 3301 app_2 ==> 3302...app_9 ==> 3309。一個1G內存的機器跑上10個MySQL是很正常的。讓10個MySQLD承擔1000個并發連接效率要比讓2個MySQLD承擔1000個效率高的多。當然,這樣也會帶來一些應用編程上的復雜度;

            3. 使用單獨的數據庫服務器(不要讓數據庫和前臺WEB服務搶內存),MySQL擁有更多的內存就可能能有效的進行結果集的緩存;在前面的啟動腳本中有一個-O key_buffer=32M參數就是用于將缺省的8M索引緩存增加到32M(當然對于)

            4. 應用盡量使用PCONNECT和polling機制,用于節省MySQL服務建立連接的開銷,但也會造成MySQL并發鏈接數過多(每個HTTPD都會對應一個MySQL線程);

            5. 表的橫向拆分:讓最常被訪問的10%的數據放在一個小表里,90%的歷史數據放在一個歸檔表里(所謂:快慢表),數據中間通過定期“搬家”和定期刪除無效數據來節省,畢竟大部分應用(比如論壇)訪問2個月前數據的幾率會非常少,而且價值也不是很高。這樣對于應用來說總是在一個比較小的結果級中進行數據選擇,比較有利于數據的緩存,不要指望MySQL中對單表記錄條數在10萬級以上還有比較高的效率。而且有時候數據沒有必要做那么精確,比如一個快表中查到了某個人發表的文章有60條結果,快表和慢表的比例是1:20,那么就可以簡單的估計這個人一共發表了1200篇。Google的搜索結果數也是一樣:對于很多上十萬的結果數,后面很多的數字都是通過一定的算法估計出來的。

            6. 數據庫字段設計:表的縱向拆分(過渡范化):將所有的定長字段(char, int等)放在一個表里,所有的變長字段(varchar,text,blob等)放在另外一個表里,2個表之間通過主鍵關聯,這樣,定長字段表可以得到很大的優化(這樣可以使用HEAP表類型,數據完全在內存中存取),這里也說明另外一個原則,對于我們來說,盡量使用定長字段可以通過空間的損失換取訪問效率的提高。在MySQL4中也出現了支持外鍵和事務的InnoDB類型表,標準的MyISAM格式表和基于HASH結構的HEAP內存表,MySQL之所以支持多種表類型,實際上是針對不同應用提供了不同的優化方式;

            7. 仔細的檢查應用的索引設計:可以在服務啟動參數中加入 --log-slow-queries[=file]用于跟蹤分析應用瓶頸,對于跟蹤服務瓶頸最簡單的方法就是用MySQL的status查看MySQL服務的運行統計和show processlist來查看當前服務中正在運行的SQL,如果某個SQL經常出現在PROCESS LIST中,一。有可能被查詢的此時非常多,二,里面有影響查詢的字段沒有索引,三,返回的結果數過多數據庫正在排序(SORTING);所以做一個腳本:比如每2秒運行以下show processlist;把結果輸出到文件中,看到底是什么查詢在吃CPU。

            8. 全文檢索:如果相應字段沒有做全文索引的話,全文檢索將是一個非常消耗CPU的功能,因為全文檢索是用不上一般數據庫的索引的,所以要進行相應字段記錄遍歷。關于全文索引可以參考一下基于Java的全文索引引擎lucene的介紹。

            9. 前臺應用的記錄緩存:比如一個經常使用數據庫認證,如果需要有更新用戶最后登陸時間的操作,最好記錄更新后就把用戶放到一個緩存中(設置2個小時后過期),這樣如果用戶在2個小時內再次使用到登陸,就直接從緩存里認證,避免了過于頻繁的數據庫操作。

            10. 查詢優先的表應該盡可能為where和order by字句中的字段加上索引,數據庫更新插入優先的應用索引越少越好。

            總之:對于任何數據庫單表記錄超過100萬條優化都是比較困難的,關鍵是要把應用能夠轉化成數據庫比較擅長的數據上限內。也就是把復雜需求簡化成比較成熟的解決方案內。

            一次優化實戰
            ============
            以下例子是對一個論壇應用進行的優化:

            1. 用Webalizer代替了原來的通過數據庫的統計。
            2. 首先通過TOP命令查看MySQL服務的CPU占用左右80%和內存占用:10M,說明數據庫的索引緩存已經用完了,修改啟動參數,增加了-O key_buffer=32M,過一段時間等數據庫穩定后看的內存占用是否達到上限。最后將緩存一直增加到64M,數據庫緩存才基本能充分使用。對于一個數據庫應用來說,把內存給數據庫比給WEB服務實用的多,因為MySQL查詢速度的提高能加快web應用從而節省并發的WEB服務所占用的內存資源。
            3. 用show processlist;統計經常出現的SQL:

              每分鐘運行一次show processlist并記錄日志:
              * * * * * (/home/mysql/bin/mysql -uuser -ppassword < /home/chedong/show_processlist.sql >>  /home/chedong/mysql_processlist.log)

              show_processlist.sql里就一句:
              show processlist;

              比如可以從日志中將包含where的字句過濾出來:
              grep where mysql_processlist.log
              如果發現有死鎖,一定要重新審視一下數據庫設計了,對于一般情況:查詢速度很慢,就將SQL where字句中沒有索引的字段加上索引,如果是排序慢就將order by字句中沒有索引的字段加上。對于有%like%的查詢,考慮以后禁用和使用全文索引加速。

            4. 還是根據show processlist;看經常有那些數據庫被頻繁使用,考慮將數據庫拆分到其他服務端口上。

            MSSQL到MySQL的數據遷移:ACCESS+MySQL ODBC Driver

            在以前的幾次數據遷移實踐過程中,我發現最簡便的數據遷移過程并不是通過專業的數據庫遷移工具,也不是MSSQL自身的DTS進行數據遷移(遷移過程中間會有很多表出錯誤警告),但通過將MSSQL數據庫通過ACCESS獲取外部數據導入到數據庫中,然后用ACCESS的表==>右鍵==>導出,制定ODBC,通過MySQL的DSN將數據導出。這樣遷移大部分數據都會非常順利,如果導出的表有索引問題,還會出添加索引提示(DTS就不行),然后剩余的工作就是在MySQL中設計字段對應的SQL腳本了。

            參考文檔:

            MySQL的參考:
            http://dev.mysql.com/doc/

            posted @ 2008-01-12 17:45 true 閱讀(305) | 評論 (0)編輯 收藏

             
            守護進程(Daemon)是運行在后臺的一種特殊進程。它獨立于控制終端并且周期性地執行某種任務或等待處理某些發生的事件。守護進程是一種很有用的進程。 Linux的大多數服務器就是用守護進程實現的。比如,Internet服務器inetd,Web服務器httpd等。同時,守護進程完成許多系統任務。比如,作業規劃進程crond,打印進程lpd等。
            守護進程的編程本身并不復雜,復雜的是各種版本的Unix的實現機制不盡相同,造成不同 Unix環境下守護進程的編程規則并不一致。需要注意,照搬某些書上的規則(特別是BSD4.3和低版本的System V)到Linux會出現錯誤的。下面將給出Linux下守護進程的編程要點和詳細實例。
            一. 守護進程及其特性
            守護進程最重要的特性是后臺運行。在這一點上DOS下的常駐內存程序TSR與之相似。其次,守護進程必須與其運行前的環境隔離開來。這些環境包括未關閉的文件描述符,控制終端,會話和進程組,工作目錄以及文件創建掩模等。這些環境通常是守護進程從執行它的父進程(特別是shell)中繼承下來的。最后,守護進程的啟動方式有其特殊之處。它可以在Linux系統啟動時從啟動腳本/etc/rc.d中啟動,可以由作業規劃進程crond啟動,還可以由用戶終端(通常是 shell)執行。
            總之,除開這些特殊性以外,守護進程與普通進程基本上沒有什么區別。因此,編寫守護進程實際上是把一個普通進程按照上述的守護進程的特性改造成為守護進程。如果對進程有比較深入的認識就更容易理解和編程了。
            二. 守護進程的編程要點
            前面講過,不同Unix環境下守護進程的編程規則并不一致。所幸的是守護進程的編程原則其實都一樣,區別在于具體的實現細節不同。這個原則就是要滿足守護進程的特性。同時,Linux是基于Syetem V的SVR4并遵循Posix標準,實現起來與BSD4相比更方便。編程要點如下;
            1. 在后臺運行。
            為避免掛起控制終端將Daemon放入后臺執行。方法是在進程中調用fork使父進程終止,讓Daemon在子進程中后臺執行。
            if(pid=fork())
            exit(0);//是父進程,結束父進程,子進程繼續
            2. 脫離控制終端,登錄會話和進程組
            有必要先介紹一下Linux中的進程與控制終端,登錄會話和進程組之間的關系:進程屬于一個進程組,進程組號(GID)就是進程組長的進程號(PID)。登錄會話可以包含多個進程組。這些進程組共享一個控制終端。這個控制終端通常是創建進程的登錄終端。
            控制終端,登錄會話和進程組通常是從父進程繼承下來的。我們的目的就是要擺脫它們,使之不受它們的影響。方法是在第1點的基礎上,調用setsid()使進程成為會話組長:
            setsid();
            說明:當進程是會話組長時setsid()調用失敗。但第一點已經保證進程不是會話組長。setsid()調用成功后,進程成為新的會話組長和新的進程組長,并與原來的登錄會話和進程組脫離。由于會話過程對控制終端的獨占性,進程同時與控制終端脫離。
            3. 禁止進程重新打開控制終端
            現在,進程已經成為無終端的會話組長。但它可以重新申請打開一個控制終端??梢酝ㄟ^使進程不再成為會話組長來禁止進程重新打開控制終端:

            if(pid=fork())
            exit(0);//結束第一子進程,第二子進程繼續(第二子進程不再是會話組長)
            4. 關閉打開的文件描述符
            進程從創建它的父進程那里繼承了打開的文件描述符。如不關閉,將會浪費系統資源,造成進程所在的文件系統無法卸下以及引起無法預料的錯誤。按如下方法關閉它們:
            for(i=0;i 關閉打開的文件描述符close(i);>
            5. 改變當前工作目錄
            進程活動時,其工作目錄所在的文件系統不能卸下。一般需要將工作目錄改變到根目錄。對于需要轉儲核心,寫運行日志的進程將工作目錄改變到特定目錄如/tmpchdir("/")
            6. 重設文件創建掩模
            進程從創建它的父進程那里繼承了文件創建掩模。它可能修改守護進程所創建的文件的存取位。為防止這一點,將文件創建掩模清除:umask(0);
            7. 處理SIGCHLD信號
            處理SIGCHLD信號并不是必須的。但對于某些進程,特別是服務器進程往往在請求到來時生成子進程處理請求。如果父進程不等待子進程結束,子進程將成為僵尸進程(zombie)從而占用系統資源。如果父進程等待子進程結束,將增加父進程的負擔,影響服務器進程的并發性能。在Linux下可以簡單地將 SIGCHLD信號的操作設為SIG_IGN。
            signal(SIGCHLD,SIG_IGN);
            這樣,內核在子進程結束時不會產生僵尸進程。這一點與BSD4不同,BSD4下必須顯式等待子進程結束才能釋放僵尸進程。
            三. 守護進程實例
            守護進程實例包括兩部分:主程序test.c和初始化程序init.c。主程序每隔一分鐘向/tmp目錄中的日志test.log報告運行狀態。初始化程序中的init_daemon函數負責生成守護進程。讀者可以利用init_daemon函數生成自己的守護進程。
            1. init.c清單

            #include < unistd.h >
            #include < signal.h >
            #include < sys/param.h >
            #include < sys/types.h >
            #include < sys/stat.h >
            void init_daemon(void)
            {
            int pid;
            int i;
            if(pid=fork())
            exit(0);//是父進程,結束父進程
            else if(pid< 0)
            exit(1);//fork失敗,退出
            //是第一子進程,后臺繼續執行
            setsid();//第一子進程成為新的會話組長和進程組長
            //并與控制終端分離
            if(pid=fork())
            exit(0);//是第一子進程,結束第一子進程
            else if(pid< 0)
            exit(1);//fork失敗,退出
            //是第二子進程,繼續
            //第二子進程不再是會話組長

            for(i=0;i< NOFILE;++i)//關閉打開的文件描述符
            close(i);
            chdir("/tmp");//改變工作目錄到/tmp
            umask(0);//重設文件創建掩模
            return;
            }
            2. test.c清單
            #include < stdio.h >
            #include < time.h >

            void init_daemon(void);//守護進程初始化函數

            main()
            {
            FILE *fp;
            time_t t;
            init_daemon();//初始化為Daemon

            while(1)//每隔一分鐘向test.log報告運行狀態
            {
            sleep(60);//睡眠一分鐘
            if((fp=fopen("test.log","a")) >=0)
            {
            t=time(0);
            fprintf(fp,"Im here at %sn",asctime(localtime(&t)) );
            fclose(fp);
            }
            }
            }
            以上程序在RedHat Linux6.0下編譯通過。步驟如下:
            編譯:gcc -g -o test init.c test.c
            執行:./test
            查看進程:ps -ef
            從輸出可以發現test守護進程的各種特性滿足上面的要求。
            posted @ 2007-11-26 10:22 true 閱讀(507) | 評論 (1)編輯 收藏

             

            一 C++ 中 string與wstring互轉

            方法一:

            string WideToMutilByte(const wstring& _src)
            {
            int nBufSize = WideCharToMultiByte(GetACP(), 0, _src.c_str(),-1, NULL, 0, 0, FALSE);

            char *szBuf = new char[nBufSize];

            WideCharToMultiByte(GetACP(), 0, _src.c_str(),-1, szBuf, nBufSize, 0, FALSE);

            string strRet(szBuf);

            delete []szBuf;
            szBuf = NULL;

            return strRet;
            }

            wstring MutilByteToWide(const string& _src)
            {
            //計算字符串 string 轉成 wchar_t 之后占用的內存字節數
            int nBufSize = MultiByteToWideChar(GetACP(),0,_src.c_str(),-1,NULL,0);

            //為 wsbuf 分配內存 BufSize 個字節
            wchar_t *wsBuf = new wchar_t[nBufSize];

            //轉化為 unicode 的 WideString
            MultiByteToWideChar(GetACP(),0,_src.c_str(),-1,wsBuf,nBufSize);

            wstring wstrRet(wsBuf);

            delete []wsBuf;
            wsBuf = NULL;

            return wstrRet;
            }

             


            轉載:csdn

            這篇文章里,我將給出幾種C++ std::string和std::wstring相互轉換的轉換方法。
             
            第一種方法:調用WideCharToMultiByte()和MultiByteToWideChar(),代碼如下(關于詳細的解釋,可以參考《windows核心編程》):
             

            #include <string>
            #include <windows.h>
            using namespace std;
            //Converting a WChar string to a Ansi string
            std::string WChar2Ansi(LPCWSTR pwszSrc)
            {
                     int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
             
                     if (nLen<= 0) return std::string("");
             
                     char* pszDst = new char[nLen];
                     if (NULL == pszDst) return std::string("");
             
                     WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
                     pszDst[nLen -1] = 0;
             
                     std::string strTemp(pszDst);
                     delete [] pszDst;
             
                     return strTemp;
            }

             
            string ws2s(wstring& inputws)
            {
                    return WChar2Ansi(inputws.c_str());
            }

             

             
            //Converting a Ansi string to WChar string


            std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen)
             
            {
                int nSize = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszSrc, nLen, 0, 0);
                if(nSize <= 0) return NULL;
             
                     WCHAR *pwszDst = new WCHAR[nSize+1];
                if( NULL == pwszDst) return NULL;
             
                MultiByteToWideChar(CP_ACP, 0,(LPCSTR)pszSrc, nLen, pwszDst, nSize);
                pwszDst[nSize] = 0;
             
                if( pwszDst[0] == 0xFEFF)                    // skip Oxfeff
                    for(int i = 0; i < nSize; i ++)
                                        pwszDst[i] = pwszDst[i+1];
             
                wstring wcharString(pwszDst);
                     delete pwszDst;
             
                return wcharString;
            }

             
            std::wstring s2ws(const string& s)
            {
                 return Ansi2WChar(s.c_str(),s.size());
            }


             
             
            第二種方法:采用ATL封裝_bstr_t的過渡:(注,_bstr_是Microsoft Specific的,所以下面代碼可以在VS2005通過,無移植性);


            #include <string>
            #include <comutil.h>
            using namespace std;
            #pragma comment(lib, "comsuppw.lib")
             
            string ws2s(const wstring& ws);
            wstring s2ws(const string& s);
             
            string ws2s(const wstring& ws)
            {
                     _bstr_t t = ws.c_str();
                     char* pchar = (char*)t;
                     string result = pchar;
                     return result;
            }

             
            wstring s2ws(const string& s)
            {
                     _bstr_t t = s.c_str();
                     wchar_t* pwchar = (wchar_t*)t;
                     wstring result = pwchar;
                     return result;
            }


             
            第三種方法:使用CRT庫的mbstowcs()函數和wcstombs()函數,平臺無關,需設定locale。


            #include <string>
            #include <locale.h>
            using namespace std;
            string ws2s(const wstring& ws)
            {
                     string curLocale = setlocale(LC_ALL, NULL);        // curLocale = "C";
             
                     setlocale(LC_ALL, "chs");
             
                     const wchar_t* _Source = ws.c_str();
                     size_t _Dsize = 2 * ws.size() + 1;
                     char *_Dest = new char[_Dsize];
                     memset(_Dest,0,_Dsize);
                     wcstombs(_Dest,_Source,_Dsize);
                     string result = _Dest;
                     delete []_Dest;
             
                     setlocale(LC_ALL, curLocale.c_str());
             
                     return result;
            }

             
            wstring s2ws(const string& s)
            {
                     setlocale(LC_ALL, "chs");
             
                     const char* _Source = s.c_str();
                     size_t _Dsize = s.size() + 1;
                     wchar_t *_Dest = new wchar_t[_Dsize];
                     wmemset(_Dest, 0, _Dsize);
                     mbstowcs(_Dest,_Source,_Dsize);
                     wstring result = _Dest;
                     delete []_Dest;
             
                     setlocale(LC_ALL, "C");
             
                     return result;
            }


            二 utf8.utf16.utf32的相互轉化

            可以參考Unicode.org 上有ConvertUTF.c和ConvertUTF.h (下載地址:http://www.unicode.org/Public/PROGRAMS/CVTUTF/

            實現文件ConvertUTF.c:(.h省)
            /**//*
             * Copyright 2001-2004 Unicode, Inc.
             *
             * Disclaimer
             *
             * This source code is provided as is by Unicode, Inc. No claims are
             * made as to fitness for any particular purpose. No warranties of any
             * kind are expressed or implied. The recipient agrees to determine
             * applicability of information provided. If this file has been
             * purchased on magnetic or optical media from Unicode, Inc., the
             * sole remedy for any claim will be exchange of defective media
             * within 90 days of receipt.
             *
             * Limitations on Rights to Redistribute This Code
             *
             * Unicode, Inc. hereby grants the right to freely use the information
             * supplied in this file in the creation of products supporting the
             * Unicode Standard, and to make copies of this file in any form
             * for internal or external distribution as long as this notice
             * remains attached.
             */

            /**//* ---------------------------------------------------------------------

                Conversions between UTF32, UTF-16, and UTF-8. Source code file.
                Author: Mark E. Davis, 1994.
                Rev History: Rick McGowan, fixes & updates May 2001.
                Sept 2001: fixed const & error conditions per
                mods suggested by S. Parent & A. Lillich.
                June 2002: Tim Dodd added detection and handling of incomplete
                source sequences, enhanced error detection, added casts
                to eliminate compiler warnings.
                July 2003: slight mods to back out aggressive FFFE detection.
                Jan 2004: updated switches in from-UTF8 conversions.
                Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.

                See the header file "ConvertUTF.h" for complete documentation.

            ------------------------------------------------------------------------ */


            #include "ConvertUTF.h"
            #ifdef CVTUTF_DEBUG
            #include <stdio.h>
            #endif

            static const int halfShift  = 10; /**//* used for shifting by 10 bits */

            static const UTF32 halfBase = 0x0010000UL;
            static const UTF32 halfMask = 0x3FFUL;

            #define UNI_SUR_HIGH_START  (UTF32)0xD800
            #define UNI_SUR_HIGH_END    (UTF32)0xDBFF
            #define UNI_SUR_LOW_START   (UTF32)0xDC00
            #define UNI_SUR_LOW_END     (UTF32)0xDFFF
            #define false       0
            #define true        1

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF32toUTF16 (
                const UTF32** sourceStart, const UTF32* sourceEnd,
                UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF32* source = *sourceStart;
                UTF16* target = *targetStart;
                while (source < sourceEnd) {
                UTF32 ch;
                if (target >= targetEnd) {
                    result = targetExhausted; break;
                }
                ch = *source++;
                if (ch <= UNI_MAX_BMP) { /**//* Target is a character <= 0xFFFF */
                    /**//* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
                    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
                    if (flags == strictConversion) {
                        --source; /**//* return to the illegal value itself */
                        result = sourceIllegal;
                        break;
                    } else {
                        *target++ = UNI_REPLACEMENT_CHAR;
                    }
                    } else {
                    *target++ = (UTF16)ch; /**//* normal case */
                    }
                } else if (ch > UNI_MAX_LEGAL_UTF32) {
                    if (flags == strictConversion) {
                    result = sourceIllegal;
                    } else {
                    *target++ = UNI_REPLACEMENT_CHAR;
                    }
                } else {
                    /**//* target is a character in range 0xFFFF - 0x10FFFF. */
                    if (target + 1 >= targetEnd) {
                    --source; /**//* Back up source pointer! */
                    result = targetExhausted; break;
                    }
                    ch -= halfBase;
                    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
                    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
                }
                }
                *sourceStart = source;
                *targetStart = target;
                return result;
            }

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF16toUTF32 (
                const UTF16** sourceStart, const UTF16* sourceEnd,
                UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF16* source = *sourceStart;
                UTF32* target = *targetStart;
                UTF32 ch, ch2;
                while (source < sourceEnd) {
                const UTF16* oldSource = source; /**//*  In case we have to back up because of target overflow. */
                ch = *source++;
                /**//* If we have a surrogate pair, convert to UTF32 first. */
                if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
                    /**//* If the 16 bits following the high surrogate are in the source buffer */
                    if (source < sourceEnd) {
                    ch2 = *source;
                    /**//* If it's a low surrogate, convert to UTF32. */
                    if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
                        ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
                        + (ch2 - UNI_SUR_LOW_START) + halfBase;
                        ++source;
                    } else if (flags == strictConversion) { /**//* it's an unpaired high surrogate */
                        --source; /**//* return to the illegal value itself */
                        result = sourceIllegal;
                        break;
                    }
                    } else { /**//* We don't have the 16 bits following the high surrogate. */
                    --source; /**//* return to the high surrogate */
                    result = sourceExhausted;
                    break;
                    }
                } else if (flags == strictConversion) {
                    /**//* UTF-16 surrogate values are illegal in UTF-32 */
                    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
                    --source; /**//* return to the illegal value itself */
                    result = sourceIllegal;
                    break;
                    }
                }
                if (target >= targetEnd) {
                    source = oldSource; /**//* Back up source pointer! */
                    result = targetExhausted; break;
                }
                *target++ = ch;
                }
                *sourceStart = source;
                *targetStart = target;
            #ifdef CVTUTF_DEBUG
            if (result == sourceIllegal) {
                fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
                fflush(stderr);
            }
            #endif
                return result;
            }

            /**//* --------------------------------------------------------------------- */

            /**//*
             * Index into the table below with the first byte of a UTF-8 sequence to
             * get the number of trailing bytes that are supposed to follow it.
             * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
             * left as-is for anyone who may want to do such conversion, which was
             * allowed in earlier algorithms.
             */
            static const char trailingBytesForUTF8[256] = {
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
            };

            /**//*
             * Magic values subtracted from a buffer value during UTF8 conversion.
             * This table contains as many values as there might be trailing bytes
             * in a UTF-8 sequence.
             */
            static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
                         0x03C82080UL, 0xFA082080UL, 0x82082080UL };

            /**//*
             * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
             * into the first byte, depending on how many bytes follow.  There are
             * as many entries in this table as there are UTF-8 sequence types.
             * (I.e., one byte sequence, two byte etc.). Remember that sequencs
             * for *legal* UTF-8 will be 4 or fewer bytes total.
             */
            static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };

            /**//* --------------------------------------------------------------------- */

            /**//* The interface converts a whole buffer to avoid function-call overhead.
             * Constants have been gathered. Loops & conditionals have been removed as
             * much as possible for efficiency, in favor of drop-through switches.
             * (See "Note A" at the bottom of the file for equivalent code.)
             * If your compiler supports it, the "isLegalUTF8" call can be turned
             * into an inline function.
             */

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF16toUTF8 (
                const UTF16** sourceStart, const UTF16* sourceEnd,
                UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF16* source = *sourceStart;
                UTF8* target = *targetStart;
                while (source < sourceEnd) {
                UTF32 ch;
                unsigned short bytesToWrite = 0;
                const UTF32 byteMask = 0xBF;
                const UTF32 byteMark = 0x80;
                const UTF16* oldSource = source; /**//* In case we have to back up because of target overflow. */
                ch = *source++;
                /**//* If we have a surrogate pair, convert to UTF32 first. */
                if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
                    /**//* If the 16 bits following the high surrogate are in the source buffer */
                    if (source < sourceEnd) {
                    UTF32 ch2 = *source;
                    /**//* If it's a low surrogate, convert to UTF32. */
                    if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
                        ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
                        + (ch2 - UNI_SUR_LOW_START) + halfBase;
                        ++source;
                    } else if (flags == strictConversion) { /**//* it's an unpaired high surrogate */
                        --source; /**//* return to the illegal value itself */
                        result = sourceIllegal;
                        break;
                    }
                    } else { /**//* We don't have the 16 bits following the high surrogate. */
                    --source; /**//* return to the high surrogate */
                    result = sourceExhausted;
                    break;
                    }
                } else if (flags == strictConversion) {
                    /**//* UTF-16 surrogate values are illegal in UTF-32 */
                    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
                    --source; /**//* return to the illegal value itself */
                    result = sourceIllegal;
                    break;
                    }
                }
                /**//* Figure out how many bytes the result will require */
                if (ch < (UTF32)0x80) {         bytesToWrite = 1;
                } else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
                } else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
                } else if (ch < (UTF32)0x110000) {  bytesToWrite = 4;
                } else {                bytesToWrite = 3;
                                    ch = UNI_REPLACEMENT_CHAR;
                }

                target += bytesToWrite;
                if (target > targetEnd) {
                    source = oldSource; /**//* Back up source pointer! */
                    target -= bytesToWrite; result = targetExhausted; break;
                }
                switch (bytesToWrite) { /**//* note: everything falls through. */
                    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 1: *--target =  (UTF8)(ch | firstByteMark[bytesToWrite]);
                }
                target += bytesToWrite;
                }
                *sourceStart = source;
                *targetStart = target;
                return result;
            }

            /**//* --------------------------------------------------------------------- */

            /**//*
             * Utility routine to tell whether a sequence of bytes is legal UTF-8.
             * This must be called with the length pre-determined by the first byte.
             * If not calling this from ConvertUTF8to*, then the length can be set by:
             *  length = trailingBytesForUTF8[*source]+1;
             * and the sequence is illegal right away if there aren't that many bytes
             * available.
             * If presented with a length > 4, this returns false.  The Unicode
             * definition of UTF-8 goes up to 4-byte sequences.
             */

            static Boolean isLegalUTF8(const UTF8 *source, int length) {
                UTF8 a;
                const UTF8 *srcptr = source+length;
                switch (length) {
                default: return false;
                /**//* Everything else falls through when "true" */
                case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
                case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
                case 2: if ((a = (*--srcptr)) > 0xBF) return false;

                switch (*source) {
                    /**//* no fall-through in this inner switch */
                    case 0xE0: if (a < 0xA0) return false; break;
                    case 0xED: if (a > 0x9F) return false; break;
                    case 0xF0: if (a < 0x90) return false; break;
                    case 0xF4: if (a > 0x8F) return false; break;
                    default:   if (a < 0x80) return false;
                }

                case 1: if (*source >= 0x80 && *source < 0xC2) return false;
                }
                if (*source > 0xF4) return false;
                return true;
            }

            /**//* --------------------------------------------------------------------- */

            /**//*
             * Exported function to return whether a UTF-8 sequence is legal or not.
             * This is not used here; it's just exported.
             */
            Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
                int length = trailingBytesForUTF8[*source]+1;
                if (source+length > sourceEnd) {
                return false;
                }
                return isLegalUTF8(source, length);
            }

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF8toUTF16 (
                const UTF8** sourceStart, const UTF8* sourceEnd,
                UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF8* source = *sourceStart;
                UTF16* target = *targetStart;
                while (source < sourceEnd) {
                UTF32 ch = 0;
                unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
                if (source + extraBytesToRead >= sourceEnd) {
                    result = sourceExhausted; break;
                }
                /**//* Do this check whether lenient or strict */
                if (! isLegalUTF8(source, extraBytesToRead+1)) {
                    result = sourceIllegal;
                    break;
                }
                /**//*
                 * The cases all fall through. See "Note A" below.
                 */
                switch (extraBytesToRead) {
                    case 5: ch += *source++; ch <<= 6; /**//* remember, illegal UTF-8 */
                    case 4: ch += *source++; ch <<= 6; /**//* remember, illegal UTF-8 */
                    case 3: ch += *source++; ch <<= 6;
                    case 2: ch += *source++; ch <<= 6;
                    case 1: ch += *source++; ch <<= 6;
                    case 0: ch += *source++;
                }
                ch -= offsetsFromUTF8[extraBytesToRead];

                if (target >= targetEnd) {
                    source -= (extraBytesToRead+1); /**//* Back up source pointer! */
                    result = targetExhausted; break;
                }
                if (ch <= UNI_MAX_BMP) { /**//* Target is a character <= 0xFFFF */
                    /**//* UTF-16 surrogate values are illegal in UTF-32 */
                    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
                    if (flags == strictConversion) {
                        source -= (extraBytesToRead+1); /**//* return to the illegal value itself */
                        result = sourceIllegal;
                        break;
                    } else {
                        *target++ = UNI_REPLACEMENT_CHAR;
                    }
                    } else {
                    *target++ = (UTF16)ch; /**//* normal case */
                    }
                } else if (ch > UNI_MAX_UTF16) {
                    if (flags == strictConversion) {
                    result = sourceIllegal;
                    source -= (extraBytesToRead+1); /**//* return to the start */
                    break; /**//* Bail out; shouldn't continue */
                    } else {
                    *target++ = UNI_REPLACEMENT_CHAR;
                    }
                } else {
                    /**//* target is a character in range 0xFFFF - 0x10FFFF. */
                    if (target + 1 >= targetEnd) {
                    source -= (extraBytesToRead+1); /**//* Back up source pointer! */
                    result = targetExhausted; break;
                    }
                    ch -= halfBase;
                    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
                    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
                }
                }
                *sourceStart = source;
                *targetStart = target;
                return result;
            }

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF32toUTF8 (
                const UTF32** sourceStart, const UTF32* sourceEnd,
                UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF32* source = *sourceStart;
                UTF8* target = *targetStart;
                while (source < sourceEnd) {
                UTF32 ch;
                unsigned short bytesToWrite = 0;
                const UTF32 byteMask = 0xBF;
                const UTF32 byteMark = 0x80;
                ch = *source++;
                if (flags == strictConversion ) {
                    /**//* UTF-16 surrogate values are illegal in UTF-32 */
                    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
                    --source; /**//* return to the illegal value itself */
                    result = sourceIllegal;
                    break;
                    }
                }
                /**//*
                 * Figure out how many bytes the result will require. Turn any
                 * illegally large UTF32 things (> Plane 17) into replacement chars.
                 */
                if (ch < (UTF32)0x80) {         bytesToWrite = 1;
                } else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
                } else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
                } else if (ch <= UNI_MAX_LEGAL_UTF32) {  bytesToWrite = 4;
                } else {                bytesToWrite = 3;
                                    ch = UNI_REPLACEMENT_CHAR;
                                    result = sourceIllegal;
                }
               
                target += bytesToWrite;
                if (target > targetEnd) {
                    --source; /**//* Back up source pointer! */
                    target -= bytesToWrite; result = targetExhausted; break;
                }
                switch (bytesToWrite) { /**//* note: everything falls through. */
                    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
                    case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
                }
                target += bytesToWrite;
                }
                *sourceStart = source;
                *targetStart = target;
                return result;
            }

            /**//* --------------------------------------------------------------------- */

            ConversionResult ConvertUTF8toUTF32 (
                const UTF8** sourceStart, const UTF8* sourceEnd,
                UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
                ConversionResult result = conversionOK;
                const UTF8* source = *sourceStart;
                UTF32* target = *targetStart;
                while (source < sourceEnd) {
                UTF32 ch = 0;
                unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
                if (source + extraBytesToRead >= sourceEnd) {
                    result = sourceExhausted; break;
                }
                /**//* Do this check whether lenient or strict */
                if (! isLegalUTF8(source, extraBytesToRead+1)) {
                    result = sourceIllegal;
                    break;
                }
                /**//*
                 * The cases all fall through. See "Note A" below.
                 */
                switch (extraBytesToRead) {
                    case 5: ch += *source++; ch <<= 6;
                    case 4: ch += *source++; ch <<= 6;
                    case 3: ch += *source++; ch <<= 6;
                    case 2: ch += *source++; ch <<= 6;
                    case 1: ch += *source++; ch <<= 6;
                    case 0: ch += *source++;
                }
                ch -= offsetsFromUTF8[extraBytesToRead];

                if (target >= targetEnd) {
                    source -= (extraBytesToRead+1); /**//* Back up the source pointer! */
                    result = targetExhausted; break;
                }
                if (ch <= UNI_MAX_LEGAL_UTF32) {
                    /**//*
                     * UTF-16 surrogate values are illegal in UTF-32, and anything
                     * over Plane 17 (> 0x10FFFF) is illegal.
                     */
                    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
                    if (flags == strictConversion) {
                        source -= (extraBytesToRead+1); /**//* return to the illegal value itself */
                        result = sourceIllegal;
                        break;
                    } else {
                        *target++ = UNI_REPLACEMENT_CHAR;
                    }
                    } else {
                    *target++ = ch;
                    }
                } else { /**//* i.e., ch > UNI_MAX_LEGAL_UTF32 */
                    result = sourceIllegal;
                    *target++ = UNI_REPLACEMENT_CHAR;
                }
                }
                *sourceStart = source;
                *targetStart = target;
                return result;
            }

            /**//* ---------------------------------------------------------------------

                Note A.
                The fall-through switches in UTF-8 reading code save a
                temp variable, some decrements & conditionals.  The switches
                are equivalent to the following loop:
                {
                    int tmpBytesToRead = extraBytesToRead+1;
                    do {
                    ch += *source++;
                    --tmpBytesToRead;
                    if (tmpBytesToRead) ch <<= 6;
                    } while (tmpBytesToRead > 0);
                }
                In UTF-8 writing code, the switches on "bytesToWrite" are
                similarly unrolled loops.

               --------------------------------------------------------------------- */

             

            三 C++ 的字符串與C#的轉化

            1)將system::String 轉化為C++的string:
            // convert_system_string.cpp
            // compile with: /clr
            #include <string>
            #include <iostream>
            using namespace std;
            using namespace System;

            void MarshalString ( String ^ s, string& os ) {
               using namespace Runtime::InteropServices;
               const char* chars =
                  (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
               os = chars;
               Marshal::FreeHGlobal(IntPtr((void*)chars));
            }

            void MarshalString ( String ^ s, wstring& os ) {
               using namespace Runtime::InteropServices;
               const wchar_t* chars =
                  (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
               os = chars;
               Marshal::FreeHGlobal(IntPtr((void*)chars));
            }

            int main() {
               string a = "test";
               wstring b = L"test2";
               String ^ c = gcnew String("abcd");

               cout << a << endl;
               MarshalString(c, a);
               c = "efgh";
               MarshalString(c, b);
               cout << a << endl;
               wcout << b << endl;
            }


            2)將System::String轉化為char*或w_char*
            // convert_string_to_wchar.cpp
            // compile with: /clr
            #include < stdio.h >
            #include < stdlib.h >
            #include < vcclr.h >

            using namespace System;

            int main() {
               String ^str = "Hello";

               // Pin memory so GC can't move it while native function is called
               pin_ptr<const wchar_t> wch = PtrToStringChars(str);
               printf_s("%S\n", wch);

               // Conversion to char* :
               // Can just convert wchar_t* to char* using one of the
               // conversion functions such as:
               // WideCharToMultiByte()
               // wcstombs_s()
               //  etc
               size_t convertedChars = 0;
               size_t  sizeInBytes = ((str->Length + 1) * 2);
               errno_t err = 0;
               char    *ch = (char *)malloc(sizeInBytes);

               err = wcstombs_s(&convertedChars,
                                ch, sizeInBytes,
                                wch, sizeInBytes);
               if (err != 0)
                  printf_s("wcstombs_s  failed!\n");

                printf_s("%s\n", ch);
            }

            posted @ 2007-11-18 19:48 true 閱讀(528) | 評論 (0)編輯 收藏

            問題描述:大部分的vs.net 2005的用戶在新建“win32項目-windows應用程序”的時候,新建的工程都通不過去,出現如下提示:
            Solution to “MSVCR80D.dll not found” by hua.
            “沒有找到MSVCR80D.dll,因此這個應用程序未能啟動。重新安裝應用程序可能會修復此問題。”的完美解決方案^_^感覺偶做的還不錯

            問題所在:由于vs.net 2005 采用了一種新的DLL方案,搞成一個exe還要配有一個manifest文件(一般在嵌入文件里了,所以看不到,不過也可以不嵌入,這樣會生產一個<程序名>.exe.manifest的文件,沒它exe自己就轉不了了:)這是個新功能,微軟弄了個新工具(mt.exe),結果不好用,好像是fat32下時間戳有問題(在ntfs下這個問題就沒有了),搞得manifest有時嵌入不到exe中(默認配置是嵌入的,所以就報錯找不到dll了。

            解決方案(3個都可以,由以第3個最帥,我做的:):
            1.    微軟對于這個問題應該也有處理,不過感覺不是很人性化。在“屬性->配置屬性->清單工具->常規“下有一個”使用FAT32解決辦法,把它選成是,就可以了。(注意:一定要先配置這個選項,然后再編譯工程,要不然還是不好用:)
            2.    找到你的工程的文件夾,如(myproject),找到其下的myproject\myproject\Debug\ myproject.rec,把它刪掉(刪掉整個Debug目錄也可以),重新編譯,搞定!
            3.    本解決方案是俺獨創的,感覺爽多了,可以直接再應用向導中配置,嚴重符合高級人機界面要求:)好,
            1)    首先找到你的vs.net安裝目錄(如我的是E:\Program Files\Microsoft Visual Studio 8),定位到Microsoft Visual Studio 8\VC\VCWizards\AppWiz\Generic\Application文件夾,備份這個Application文件夾,不然一會你自己改咂了我可不管?。海?br>2)    打開html\2052,看到兩個文件了吧,就那個AppSettings.htm了,這個管著你的那個配置向導的界面,用UE(不要告訴我你不知道ue啥東西,baidu it)打開,在266行“                </SPAN>”后回車,然后插入一下內容:
            <!-- this (hua)section is added by HUA. -->
                                <br><br><br><br><br>
                                
                            <span class="itemTextTop" id="FILE_SYSTEM_SPAN" title="">選擇你所使用的文件系統:
                                
                                   <P CLASS="Spacer"> </P>
                                
                                    <INPUT TYPE="radio" CLASS="Radio" checked onPropertyChange="" NAME="filesystem" ID="FAT32" ACCESSKEY="F" TITLE="FAT32">
                                    <DIV CLASS="itemTextRadioB" ID="FAT32_DIV" TITLE="FAT32">
                                    <LABEL FOR="FAT32" ID="FAT32_LABEL">FAT32(<U>F</U>)</LABEL>
                                    </DIV>

                                  <BR>

                                    <INPUT TYPE="radio" CLASS="Radio" onPropertyChange="" NAME="filesystem" ID="NTFS" ACCESSKEY="N" TITLE="NTFS">
                                    <DIV CLASS="itemTextRadioB" ID="NTFS_DIV" TITLE="NTFS">
                                    <LABEL FOR="NTFS" ID="NTFS_LABEL">NTFS(<U>N</U>)</LABEL>
                                    </DIV>
                            </span>
            <!-- end of (hua)section -->
            好,保存關閉,這個改完了,準備下一個。

            3)    打開scripts\2052,這里就一個文件,ue打開它,找到138行“        var bATL = wizard.FindSymbol("SUPPORT_ATL");”其后回車,插入如下內容:
            // this (hua)section is added by HUA.
                    var MFTool = config.Tools("VCManifestTool");
                    MFTool.UseFAT32Workaround = true;
            // end of (hua)section    
                    好,繼續找到210行(源文件的210,你加了上邊的語句就不是210了:)“        config = proj.Object.Configurations.Item("Release");”注意這次要在這行“前邊”加如下內容:
            // this (hua)section is added by HUA.
                    if(bFAT32)
                    {
                        var MFTool = config.Tools("VCManifestTool");
                        MFTool.UseFAT32Workaround = true;
                    }
            // end of (hua)section    
            好了,終于都改完了,打開你的vs.net 2005新建一個win32應用程序看看吧,效果還不錯吧:)為了這個問題,耽誤了我一天的考研復習時間,希望大家能用的上。
            另外附個國外的bbs:http://forums.microsoft.com/MSDN/default.aspx?SiteID=1
            Msdn的,肯定不錯了,上邊有vs.net的開發人員活動,都是很官方的東西,大家可以看看,不過英語要夠好哦:)
            posted @ 2007-11-17 01:37 true 閱讀(592) | 評論 (0)編輯 收藏

            (一) 先講一下XML中的物殊字符,手動填寫時注意一下。

            字符                  字符實體
            &                      &amp;或&
            '                      &apos;或'
            >                      &gt;或>
            <                      &lt;或&<
            "                       &quot;或"

            (二) CMarkup類的源代碼。

            這是目前的最新版本;

            這是官網示例文件,取出里面的Markup.cpp和Markup.h,導入你的工程里面,CMarkup類就可以用了;

            下載地址:http://www.firstobject.com/Markup83.zip

            (三) 創建一個XML文檔。

            CMarkup xml;
            xml.AddElem( "ORDER" );
            xml.AddChildElem( "ITEM" );
            xml.IntoElem();
            xml.AddChildElem( "SN", "132487A-J" );
            xml.AddChildElem( "NAME", "crank casing" );
            xml.AddChildElem( "QTY", "1" );
            xml.Save("c:\\UserInfo.xml");

            效果如下:

            <ORDER>
            <ITEM>
            <SN>132487A-J</SN>
            <NAME>crank casing</NAME>
            <QTY>1</QTY>
            </ITEM>
            </ORDER>
            (四) 瀏覽特定元素
            CMarkup xml;
            xml.Load("UserInfo.xml");
            while ( xml.FindChildElem("ITEM") ) {     xml.IntoElem();     xml.FindChildElem( "SN" );     CString csSN = xml.GetChildData();     xml.FindChildElem( "QTY" );     int nQty = atoi( xml.GetChildData() );     xml.OutOfElem(); }
            (五)增加元素和屬性
            添加在最后面,使用的是AddElem;添加在最前面,使用InsertElem。
            CMarkup xml;
            xml.Load("c:\\UserInfo.xml");
            xml.AddElem( "ORDER" );
            xml.IntoElem(); // 進入 ORDER



                xml.AddElem( "ITEM" );     xml.IntoElem(); // 進入 ITEM     xml.AddElem( "SN", "4238764-A" ); //添加元素     xml.AddElem( "NAME", "bearing" );//添加元素     xml.AddElem( "QTY", "15" );//添加元素     xml.OutOfElem(); // 退出 ITEM 
            xml.AddElem( "SHIPMENT" );
            xml.IntoElem(); // 進入 SHIPMENT
            xml.AddElem( "POC" );//添加元素
            xml.SetAttrib( "type", "non-emergency");//添加屬性
            xml.IntoElem(); // 進入 POC
            xml.AddElem( "NAME", "John Smith");//添加元素
            xml.AddElem( "TEL", "555-1234");//添加元素
            xml.Save("c:\\UserInfo.xml");

             

            效果如下:

            <ORDER>
            <ITEM>
            <SN>132487A-J</SN>
            <NAME>crank casing</NAME>
            <QTY>1</QTY>
            </ITEM>
            <ITEM>
            <SN>4238764-A</SN>
            <NAME>bearing</NAME>
            <QTY>15</QTY>
            </ITEM>
            <SHIPMENT>
            <POC type="non-emergency">
            <NAME>John Smith</NAME>
            <TEL>555-1234</TEL>
            </POC>
            </SHIPMENT>
            </ORDER>

            (六) 修改元素和屬性

            如將POC中的屬性type改成:change;

            元素TEL改成:123456789

                   CMarkup xml;
             if (xml.Load("UserInfo.xml"))
             {
              CString strUserID = _T("");
              xml.ResetMainPos();
              if (xml.FindChildElem("SHIPMENT"))
              {
               xml.IntoElem();
               if (xml.FindChildElem("POC"))
               {
                xml.IntoElem();
                CString str_type=xml.GetAttrib("type");
                MessageBox(str_type);
                xml.SetAttrib("type","change");
                strUserID = xml.GetData();
                
                if (xml.FindChildElem("TEL"))
                {
                 xml.IntoElem();
                 xml.SetData("123456789");
                 xml.Save("UserInfo.xml");
                 return;
                }
               }
              }
             }

            (七)刪除元素:

            刪除SN=132487A-J的項目。

            CMarkup xml;
             if (xml.Load("UserInfo.xml"))
             {
              CString strUserID = _T("");
              xml.ResetMainPos();
              if (xml.FindChildElem("ITEM"))
              {
               xml.IntoElem();
               CString str_sn;
               xml.FindChildElem("SN");
               str_sn=xml.GetChildData();
               if(str_sn=="132487A-J")
               {
                xml.RemoveElem();
                xml.Save("UserInfo.xml");
               }
              }
             }

            posted @ 2007-11-15 22:02 true 閱讀(878) | 評論 (0)編輯 收藏

            awk 用法小結

            awk 用法:awk ' pattern {action} '

            變量名 含義
            ARGC 命令行變元個數
            ARGV 命令行變元數組
            FILENAME 當前輸入文件名
            FNR 當前文件中的記錄號
            FS 輸入域分隔符,默認為一個空格
            RS 輸入記錄分隔符
            NF 當前記錄里域個數
            NR 到目前為止記錄數
            OFS 輸出域分隔符
            ORS 輸出記錄分隔符

            1、awk '/101/' file 顯示文件file中包含101的匹配行。
            awk '/101/,/105/' file
            awk '$1 == 5' file
            awk '$1 == "CT"' file 注意必須帶雙引號
            awk '$1 * $2 >100 ' file
            awk '$2 >5 && $2<=15' file
            2、awk '{print NR,NF,$1,$NF,}' file 顯示文件file的當前記錄號、域數和每一行的第一個和最后一個域。
            awk '/101/ {print $1,$2 + 10}' file 顯示文件file的匹配行的第一、二個域加10。
            awk '/101/ {print $1$2}' file
            awk '/101/ {print $1 $2}' file 顯示文件file的匹配行的第一、二個域,但顯示時域中間沒有分隔符。
            3、df | awk '$4>1000000 ' 通過管道符獲得輸入,如:顯示第4個域滿足條件的行。
            4、awk -F "|" '{print $1}' file 按照新的分隔符“|”進行操作。
            awk 'BEGIN { FS="[: \t|]" }
            {print $1,$2,$3}' file 通過設置輸入分隔符(FS="[: \t|]")修改輸入分隔符。

            Sep="|"
            awk -F $Sep '{print $1}' file 按照環境變量Sep的值做為分隔符。
            awk -F '[ :\t|]' '{print $1}' file 按照正則表達式的值做為分隔符,這里代表空格、:、TAB、|同時做為分隔符。
            awk -F '[][]' '{print $1}' file 按照正則表達式的值做為分隔符,這里代表[、]
            5、awk -f awkfile file 通過文件awkfile的內容依次進行控制。
            cat awkfile
            /101/{print "\047 Hello! \047"} --遇到匹配行以后打印 ' Hello! '.\047代表單引號。
            {print $1,$2} --因為沒有模式控制,打印每一行的前兩個域。
            6、awk '$1 ~ /101/ {print $1}' file 顯示文件中第一個域匹配101的行(記錄)。
            7、awk 'BEGIN { OFS="%"}
            {print $1,$2}' file 通過設置輸出分隔符(OFS="%")修改輸出格式。
            8、awk 'BEGIN { max=100 ;print "max=" max} BEGIN 表示在處理任意行之前進行的操作。
            {max=($1 >max ?$1:max); print $1,"Now max is "max}' file 取得文件第一個域的最大值。
            (表達式1?表達式2:表達式3 相當于:
            if (表達式1)
            表達式2
            else
            表達式3
            awk '{print ($1>4 ? "high "$1: "low "$1)}' file
            9、awk '$1 * $2 >100 {print $1}' file 顯示文件中第一個域匹配101的行(記錄)。
            10、awk '{$1 == 'Chi' {$3 = 'China'; print}' file 找到匹配行后先將第3個域替換后再顯示該行(記錄)。
            awk '{$7 %= 3; print $7}' file 將第7域被3除,并將余數賦給第7域再打印。
            11、awk '/tom/ {wage=$2+$3; printf wage}' file 找到匹配行后為變量wage賦值并打印該變量。
            12、awk '/tom/ {count++;}
            END {print "tom was found "count" times"}' file END表示在所有輸入行處理完后進行處理。
            13、awk 'gsub(/\$/,"");gsub(/,/,""); cost+=$4;
            END {print "The total is $" cost>"filename"}' file gsub函數用空串替換$和,再將結果輸出到filename中。
            1 2 3 $1,200.00
            1 2 3 $2,300.00
            1 2 3 $4,000.00

            awk '{gsub(/\$/,"");gsub(/,/,"");
            if ($4>1000&&$4<2000) c1+=$4;
            else if ($4>2000&&$4<3000) c2+=$4;
            else if ($4>3000&&$4<4000) c3+=$4;
            else c4+=$4; }
            END {printf "c1=[%d];c2=[%d];c3=[%d];c4=[%d]\n",c1,c2,c3,c4}"' file
            通過if和else if完成條件語句

            awk '{gsub(/\$/,"");gsub(/,/,"");
            if ($4>3000&&$4<4000) exit;
            else c4+=$4; }
            END {printf "c1=[%d];c2=[%d];c3=[%d];c4=[%d]\n",c1,c2,c3,c4}"' file
            通過exit在某條件時退出,但是仍執行END操作。
            awk '{gsub(/\$/,"");gsub(/,/,"");
            if ($4>3000) next;
            else c4+=$4; }
            END {printf "c4=[%d]\n",c4}"' file
            通過next在某條件時跳過該行,對下一行執行操作。


            14、awk '{ print FILENAME,$0 }' file1 file2 file3>fileall 把file1、file2、file3的文件內容全部寫到fileall中,格式為
            打印文件并前置文件名。
            15、awk ' $1!=previous { close(previous); previous=$1 }
            {print substr($0,index($0," ") +1)>$1}' fileall 把合并后的文件重新分拆為3個文件。并與原文件一致。
            16、awk 'BEGIN {"date"|getline d; print d}' 通過管道把date的執行結果送給getline,并賦給變量d,然后打印。
            17、awk 'BEGIN {system("echo \"Input your name:\\c\""); getline d;print "\nYour name is",d,"\b!\n"}'
            通過getline命令交互輸入name,并顯示出來。
            awk 'BEGIN {FS=":"; while(getline< "/etc/passwd" >0) { if($1~"050[0-9]_") print $1}}'
            打印/etc/passwd文件中用戶名包含050x_的用戶名。

            18、awk '{ i=1;while(i<NF) {print NF,$i;i++}}' file 通過while語句實現循環。
            awk '{ for(i=1;i<NF;i++) {print NF,$i}}' file 通過for語句實現循環。
            type file|awk -F "/" '
            { for(i=1;i<NF;i++)
            { if(i==NF-1) { printf "%s",$i }
            else { printf "%s/",$i } }}' 顯示一個文件的全路徑。
            用for和if顯示日期
            awk 'BEGIN {
            for(j=1;j<=12;j++)
            { flag=0;
            printf "\n%d月份\n",j;
            for(i=1;i<=31;i++)
            {
            if (j==2&&i>28) flag=1;
            if ((j==4||j==6||j==9||j==11)&&i>30) flag=1;
            if (flag==0) {printf "%02d%02d ",j,i}
            }
            }
            }'
            19、在awk中調用系統變量必須用單引號,如果是雙引號,則表示字符串
            Flag=abcd
            awk '{print '$Flag'}' 結果為abcd
            awk '{print "$Flag"}' 結果為$Flag
            posted @ 2007-11-13 12:02 true 閱讀(403) | 評論 (0)編輯 收藏

            一、 簡單查詢

              簡單的Transact-SQL查詢只包括選擇列表、FROM子句和WHERE子句。它們分別說明所查詢列、查詢的表或視圖、以及搜索條件等。
              例如,下面的語句查詢testtable表中姓名為"張三"的nickname字段和email字段。

               SELECT nickname,email
              FROM testtable
              WHERE name='張三'

              (一) 選擇列表

              選擇列表(select_list)指出所查詢列,它可以是一組列名列表、星號、表達式、變量(包括局部變量和全局變量)等構成。

              1、選擇所有列

              例如,下面語句顯示testtable表中所有列的數據:

               SELECT *
              FROM testtable

              2、選擇部分列并指定它們的顯示次序

              查詢結果集合中數據的排列順序與選擇列表中所指定的列名排列順序相同。
              例如:

               SELECT nickname,email
              FROM testtable

              3、更改列標題

              在選擇列表中,可重新指定列標題。定義格式為:
              列標題=列名
              列名 列標題
              如果指定的列標題不是標準的標識符格式時,應使用引號定界符,例如,下列語句使用漢字顯示列標題:

               SELECT 昵稱=nickname,電子郵件=email
              FROM testtable

              4、刪除重復行

              SELECT語句中使用ALL或DISTINCT選項來顯示表中符合條件的所有行或刪除其中重復的數據行,默認為ALL。使用DISTINCT選項時,對于所有重復的數據行在SELECT返回的結果集合中只保留一行。

              5、限制返回的行數

              使用TOP n [PERCENT]選項限制返回的數據行數,TOP n說明返回n行,而TOP n PERCENT時,說明n是表示一百分數,指定返回的行數等于總行數的百分之幾。
              例如:

               SELECT TOP 2 *
              FROM testtable
              SELECT TOP 20 PERCENT *
              FROM testtable

              (二)FROM子句

              FROM子句指定SELECT語句查詢及與查詢相關的表或視圖。在FROM子句中最多可指定256個表或視圖,它們之間用逗號分隔。
              在FROM子句同時指定多個表或視圖時,如果選擇列表中存在同名列,這時應使用對象名限定這些列所屬的表或視圖。例如在usertable和citytable表中同時存在cityid列,在查詢兩個表中的cityid時應使用下面語句格式加以限定:

                SELECT username,citytable.cityid
              FROM usertable,citytable
              WHERE usertable.cityid=citytable.cityid

              在FROM子句中可用以下兩種格式為表或視圖指定別名:
              表名 as 別名
              表名 別名

              (二) FROM子句

              FROM子句指定SELECT語句查詢及與查詢相關的表或視圖。在FROM子句中最多可指定256個表或視圖,它們之間用逗號分隔。
              在FROM子句同時指定多個表或視圖時,如果選擇列表中存在同名列,這時應使用對象名限定這些列所屬的表或視圖。例如在usertable和citytable表中同時存在cityid列,在查詢兩個表中的cityid時應使用下面語句格式加以限定:

               SELECT username,citytable.cityid
              FROM usertable,citytable
              WHERE usertable.cityid=citytable.cityid

              在FROM子句中可用以下兩種格式為表或視圖指定別名:
              表名 as 別名
              表名 別名
              例如上面語句可用表的別名格式表示為:

               SELECT username,b.cityid
              FROM usertable a,citytable b
              WHERE a.cityid=b.cityid

              SELECT不僅能從表或視圖中檢索數據,它還能夠從其它查詢語句所返回的結果集合中查詢數據。

              例如:

                SELECT a.au_fname+a.au_lname
              FROM authors a,titleauthor ta
              (SELECT title_id,title
              FROM titles
              WHERE ytd_sales>10000
              ) AS t
              WHERE a.au_id=ta.au_id
              AND ta.title_id=t.title_id

              此例中,將SELECT返回的結果集合給予一別名t,然后再從中檢索數據。

              (三) 使用WHERE子句設置查詢條件

              WHERE子句設置查詢條件,過濾掉不需要的數據行。例如下面語句查詢年齡大于20的數據:

               SELECT *
              FROM usertable
              WHERE age>20

              WHERE子句可包括各種條件運算符:
              比較運算符(大小比較):>、>=、=、<、<=、<>、!>、!<
              范圍運算符(表達式值是否在指定的范圍):BETWEEN...AND...
              NOT BETWEEN...AND...
              列表運算符(判斷表達式是否為列表中的指定項):IN (項1,項2......)
              NOT IN (項1,項2......)
              模式匹配符(判斷值是否與指定的字符通配格式相符):LIKE、NOT LIKE
              空值判斷符(判斷表達式是否為空):IS NULL、NOT IS NULL
              邏輯運算符(用于多條件的邏輯連接):NOT、AND、OR

              1、范圍運算符例:age BETWEEN 10 AND 30相當于age>=10 AND age<=30
              2、列表運算符例:country IN ('Germany','China')
              3、模式匹配符例:常用于模糊查找,它判斷列值是否與指定的字符串格式相匹配。可用于char、varchar、text、ntext、datetime和smalldatetime等類型查詢。
              可使用以下通配字符:
              百分號%:可匹配任意類型和長度的字符,如果是中文,請使用兩個百分號即%%。
              下劃線_:匹配單個任意字符,它常用來限制表達式的字符長度。
              方括號[]:指定一個字符、字符串或范圍,要求所匹配對象為它們中的任一個。[^]:其取值也[] 相同,但它要求所匹配對象為指定字符以外的任一個字符。
              例如:
              限制以Publishing結尾,使用LIKE '%Publishing'
              限制以A開頭:LIKE '[A]%'
              限制以A開頭外:LIKE '[^A]%'

              4、空值判斷符例WHERE age IS NULL

              5、邏輯運算符:優先級為NOT、AND、OR

              (四)查詢結果排序

              使用ORDER BY子句對查詢返回的結果按一列或多列排序。ORDER BY子句的語法格式為:
              ORDER BY {column_name [ASC|DESC]} [,...n]
              其中ASC表示升序,為默認值,DESC為降序。ORDER BY不能按ntext、text和image數據類型進行排
              序。
              例如:

                SELECT *
              FROM usertable
              ORDER BY age desc,userid ASC

              另外,可以根據表達式進行排序。

              二、 聯合查詢

              UNION運算符可以將兩個或兩個以上上SELECT語句的查詢結果集合合并成一個結果集合顯示,即執行聯合查詢。UNION的語法格式為:

                select_statement
              UNION [ALL] selectstatement
              [UNION [ALL] selectstatement][...n]

              其中selectstatement為待聯合的SELECT查詢語句。

              ALL選項表示將所有行合并到結果集合中。不指定該項時,被聯合查詢結果集合中的重復行將只保留一行。

              聯合查詢時,查詢結果的列標題為第一個查詢語句的列標題。因此,要定義列標題必須在第一個查詢語句中定義。要對聯合查詢結果排序時,也必須使用第一查詢語句中的列名、列標題或者列序號。

              在使用UNION 運算符時,應保證每個聯合查詢語句的選擇列表中有相同數量的表達式,并且每個查詢選擇表達式應具有相同的數據類型,或是可以自動將它們轉換為相同的數據類型。在自動轉換時,對于數值類型,系統將低精度的數據類型轉換為高精度的數據類型。

              在包括多個查詢的UNION語句中,其執行順序是自左至右,使用括號可以改變這一執行順序。例如:

              查詢1 UNION (查詢2 UNION 查詢3)

              三、連接查詢

              通過連接運算符可以實現多個表查詢。連接是關系數據庫模型的主要特點,也是它區別于其它類型數據庫管理系統的一個標志。

              在關系數據庫管理系統中,表建立時各數據之間的關系不必確定,常把一個實體的所有信息存放在一個表中。當檢索數據時,通過連接操作查詢出存放在多個表中的不同實體的信息。連接操作給用戶帶來很大的靈活性,他們可以在任何時候增加新的數據類型。為不同實體創建新的表,爾后通過連接進行查詢。

              連接可以在SELECT 語句的FROM子句或WHERE子句中建立,似是而非在FROM子句中指出連接時有助于將連接操作與WHERE子句中的搜索條件區分開來。所以,在Transact-SQL中推薦使用這種方法。

              SQL-92標準所定義的FROM子句的連接語法格式為:

               FROM join_table join_type join_table
              [ON (join_condition)]

              其中join_table指出參與連接操作的表名,連接可以對同一個表操作,也可以對多表操作,對同一個表操作的連接又稱做自連接。

              join_type 指出連接類型,可分為三種:內連接、外連接和交叉連接。內連接(INNER JOIN)使用比較運算符進行表間某(些)列數據的比較操作,并列出這些表中與連接條件相匹配的數據行。根據所使用的比較方式不同,內連接又分為等值連接、自然連接和不等連接三種。外連接分為左外連接(LEFT OUTER JOIN或LEFT JOIN)、右外連接(RIGHT OUTER JOIN或RIGHT JOIN)和全外連接(FULL OUTER JOIN或FULL JOIN)三種。與內連接不同的是,外連接不只列出與連接條件相匹配的行,而是列出左表(左外連接時)、右表(右外連接時)或兩個表(全外連接時)中所有符合搜索條件的數據行。

              交叉連接(CROSS JOIN)沒有WHERE 子句,它返回連接表中所有數據行的笛卡爾積,其結果集合中的數據行數等于第一個表中符合查詢條件的數據行數乘以第二個表中符合查詢條件的數據行數。

              連接操作中的ON (join_condition) 子句指出連接條件,它由被連接表中的列和比較運算符、邏輯運算符等構成。

              無論哪種連接都不能對text、ntext和image數據類型列進行直接連接,但可以對這三種列進行間接連接。例如:

               SELECT p1.pub_id,p2.pub_id,p1.pr_info
              FROM pub_info AS p1 INNER JOIN pub_info AS p2
              ON DATALENGTH(p1.pr_info)=DATALENGTH(p2.pr_info)

              (一)內連接
              內連接查詢操作列出與連接條件匹配的數據行,它使用比較運算符比較被連接列的列值。內連接分三種:
              1、等值連接:在連接條件中使用等于號(=)運算符比較被連接列的列值,其查詢結果中列出被連接表中的所有列,包括其中的重復列。
              2、不等連接: 在連接條件使用除等于運算符以外的其它比較運算符比較被連接的列的列值。這些運算符包括>、>=、<=、<、!>、!<和<>。
              3、自然連接:在連接條件中使用等于(=)運算符比較被連接列的列值,但它使用選擇列表指出查詢結果集合中所包括的列,并刪除連接表中的重復列。
              例,下面使用等值連接列出authors和publishers表中位于同一城市的作者和出版社:

               SELECT *
              FROM authors AS a INNER JOIN publishers AS p
              ON a.city=p.city
              又如使用自然連接,在選擇列表中刪除authors 和publishers 表中重復列(city和state):
              SELECT a.*,p.pub_id,p.pub_name,p.country
              FROM authors AS a INNER JOIN publishers AS p
              ON a.city=p.city

              (二)外連接
              內連接時,返回查詢結果集合中的僅是符合查詢條件( WHERE 搜索條件或 HAVING 條件)和連接條件的行。而采用外連接時,它返回到查詢結果集合中的不僅包含符合連接條件的行,而且還包括左表(左外連接時)、右表(右外連接時)或兩個邊接表(全外連接)中的所有數據行。如下面使用左外連接將論壇內容和作者信息連接起來:

               SELECT a.*,b.* FROM luntan LEFT JOIN usertable as b
              ON a.username=b.username

              下面使用全外連接將city表中的所有作者以及user表中的所有作者,以及他們所在的城市:

                SELECT a.*,b.*
              FROM city as a FULL OUTER JOIN user as b
              ON a.username=b.username

              (三)交叉連接
              交叉連接不帶WHERE 子句,它返回被連接的兩個表所有數據行的笛卡爾積,返回到結果集合中的數據行數等于第一個表中符合查詢條件的數據行數乘以第二個表中符合查詢條件的數據行數。例,titles表中有6類圖書,而publishers表中有8家出版社,則下列交叉連接檢索到的記錄數將等于6*8=48行。
               SELECT type,pub_name
              FROM titles CROSS JOIN publishers
              ORDER BY type

            修改字段屬性

            alter table tablename modify id int(10) unsigned auto_increment primary key not null

            修改默認值

            alter table tablename alter id default 0

            給字段增加primary key

            alter table tablename add primary key(id);

            刪除primary key

            1、alter table tablename drop primary key;

            2、drop primary key on tablename;


            查看table表結構

            show create table tableName;


            修改table表數據引擎

            alter table tableName ENGINE = MyISAM (InnoDB);

            增加字段
            ALTER TABLE `table` ADD `field` INT(11) UNSIGNED NOT NULL

            刪除字段

            alert table 'table' drop 'field'

             

            posted @ 2007-09-05 14:49 true 閱讀(591) | 評論 (0)編輯 收藏

            MySQL使用tips

            作者:葉金榮 (Email:imysql@gmail.com) 來源:http://imysql.cn (2006-07-12 17:05:03)


            1、用mysql內置函數轉換ip地址和數字
            利用兩個內置函數
            inet_aton:將ip地址轉換成數字型
            inet_ntoa:將數字型轉換成ip地址

            2、充分利用mysql內置的format函數
            尤其是在處理字符格式的時候,例如將12345轉換成12,345這樣的,只要用:format(12345,0)即可,如果用format(12345,2)則顯示的是12,345.00了...

            3、利用mysql的內置函數處理時間戳問題
            eg : select FROM_UNIXTIME(UNIX_TIMESTAMP(),'%Y %D %M %h:%i:%s %x');
            結果: 2004 3rd August 03:35:48 2004

            4、利用mysql_convert_table_format轉換表類型
            需要DBI和DBD的mysql相關模塊支持才能用,例子:
            mysql_convert_table_format --user=root --password='xx' --type=myisam test yejr

            5、修改mysql表中的字段名
            alter table tb_name change old_col new_col definition...

            6、利用臨時變量
            select @var1:=a1+a2 as a_sum,@var2:=b1+b2 as b_sum,@var1+@var2 as total_sum from test_table xxx;

            7、用int類型存儲ip地址
            原先錯誤的認為必須用bigint才夠,后來發現使用int unsigned類型就足夠了。 :)

            8、CREATE TABLE IF NOT EXISTS ... select 語法局限
            盡管只是對目標表的insert操作,但是‘居然’不允許源表的insert操作,真是莫名其妙

            9、利用IF函數快速修改ENUM字段值
            一個例子:
            update rule set enable = if('0' = enable,'1','0') where xxx;
            enable 類型:enum('0','1') not null default '0'

            10、事務無法嵌套

            11、避免長時間的sleep連接造成的連接數超出問題
            設定全局變量 wait_timeout 和 interactive_timeout 為比較小的值,例如 10(s),就能使每個sleep連接在10s之后如果還沒有查詢的話自動斷開。

            (http://www.fanqiang.com)
            posted @ 2007-08-30 10:20 true 閱讀(260) | 評論 (0)編輯 收藏

            http://www.codeproject.com/macro/KingsTools.asp

            Kings Tools

            Kings Tools

            Introduction

            As good as Visual Studio .NET is, I still miss some features in it. But MS knew that they couldn't fulfill every wish so they provided a way to write addins. That's what I've done. Sure, most of the functions in my Tools could also be done with macros, but I wanted them all packed together with an installer.

            Tools

            • Run Doxygen
            • Insert Doxygen comments
            • Build Solution stats
            • Dependency Graph
            • Inheritance Graph
            • Swap .h<->.cpp
            • Colorize
            • } End of
            • #region/#endregion for c++
            • Search the web

            Run Doxygen

            This command first pops up a dialog box in which you can configure the output Doxygen should produce. For those who don't know Doxygen: it's a free tool to generate source documentations. It can produce documentation in different formats like html and even windows help format! See http://www.doxygen.org/ for details. Since the dialog box doesn't offer all possible settings for doxygen, you can always edit the file Doxyfile.cfg manually which is created the first time you run it. All settings in that file override the settings you enter in the dialog box.

            Doxygen configuration dialog

            If you set Doxygen to generate html output, the resulting index.html is opened inside the IDE. A winhelp output (index.chm) will be opened outside the IDE.

            The command available from the Tools menu builds the documentation for the whole solution. If you don't want that for example if you have several third party projects in your solution then you can build the documentation also for single projects. To do that the KingsTools add a command to the right click menu in the solution explorer.

            If you want to update Doxygen to a newer version (as soon as one is released) simply overwrite the doxygen.exe in the installation directory. The same applies to the dot.exe.

            TODO: find a way to integrate the generated windows help file into VS help.

            Insert Doxygen comments

            Doxygen needs comments that follow certain conventions to build documentation from. This part of the tools inserts them for you. Either from the right click menu in the code editor window or from the submenu under Tools->Kings Tools. Just place the caret over a method or class header. The inserted comment for a method or function would look like this:

            				/**
            *
            * \param one
            * \param two
            * \param three
            * \return
            */
            BOOL myfunction(int one, int two, int three);
            

            You now have to simply insert a description in the second comment line and descriptions for each parameter of the function/method. And of course a description of the return value.

            You can customize the function comments by editing the files "functionheadertop.txt", "functionparams.txt" and "functionheaderbottom.txt". Please read the comments inside those files on how to do that. If you don't want to change the function comments for all your projects then you can place any of those files into your project directory (that way it will be used for your project) or inside the folder of your source files (that way it will be used only for the files inside that specific folder).

            The inserted comment for a class looks like this:

            				/**
            * \ingroup projectname
            *
            * \par requirements
            * win98 or later, win2k or later, win95 with IE4 or later, winNT4 with IE4
            * or later
            *
            * \author user
            *
            * \par license
            * This code is absolutely free to use and modify. The code is provided
            * "as is" with no expressed or implied warranty. The author accepts no
            * liability if it causes any damage to your computer, causes your pet to
            * fall ill, increases baldness or makes your car start emitting strange
            * noises when you start it up. This code has no bugs, just undocumented
            * features!
            *
            * \version 1.0
            * \date 06-2002
            * \todo
            * \bug
            * \warning
            *
            */
            class CRegBase
            

            The '\ingroup projectname' means that the class is inside the project 'projectname'. That statement helps Doxygen to group classes together. Insert the description of the class right after that statement. If you want to include pictures to illustrate the class, use '\image html "picture.jpg"'. For more helpful tags you can use please check out the Doxygen website. The '\par requirements' section you have to modify yourself to fit the truth of your class. It's not necessary for Doxygen, but I found it very useful to give that information inside a class documentation. The name after the '\author' tag is the currently logged in user. Maybe you want to change that too to include an email address.

            You can customize the class comments by editing the file "classheader.txt" Please read the comments inside that file on how to do that. If you don't want to change the class comments for all your projects then you can place that files into your project directory (that way it will be used for your project) or inside the folder of your source files (that way it will be used only for the files inside that specific folder).

            The last few tags should be self-explanatory. Under the line '\version' I usually insert short descriptions of what changed between versions.

            Build Solution stats

            This is a simple line counter. It counts all the lines of all files in your solution, grouped by projects. The generated html file with the counted lines (code, comments, empty) is then opened in the IDE. Since I haven't found a way to add a file directly to a solution and not to a project the file is just opened for view in the IDE.

            Dependency and Inheritance graph

            These two commands build graphs of the class relations in your solution. See my previous article about this. The difference to my old tool is that it now generates graphs for all projects in the solution and puts all the graphs in one single html page.

            Swap .h<->.cpp

            This is something a simple macro could also do: it swaps between header and code files. For better accessibility it also is on the right click menu of the code editor. Really nothing special but it can be useful sometimes.

            Colorize

            This tool goes through all files of the current solution and looks for class, function and macronames. It then writes them to a usertype.dat file, makes the IDE to read that file and deletes it again. After you run this tool, all class, function and macronames of your solution appear colored in the code editor. Default color is the same color as normal keywords, but you can change that under Tools->Options, in the Options dialog select Environment->Fonts and Colors.

            If you don't want the colors anymore, just run the command 'disable coloring' and everything will be in normal colors again. I didn't want to overwrite some possible usertype.dat file already created by some user so the tool simply creates a temporary usertype.dat file instead. If you want to have the colors again the next time the IDE starts, you either have to rerun the command (doesn't take very long to execute) or change the code of the tool yourself.

            } End of

            Have you ever wrote a bunch of code which looked like this:

            Braces without comments

            Ok, I admit this isn't a very good style of programming, but sometimes it can't be avoided. And in those cases the code is horrible to read because you don't know which closing brace belongs to which opening statement without scrolling or using the macro 'Edit.GotoBrace' several times. This tool provides a function which inserts comments after the closing brace automatically. The code snippet above would look like this:

            Braces with comments

            Comments are only inserted for closing braces of if, while, for and switch statements.

            If you don't want to insert comments automatically while editing, you can turn off this function. If you just don't want those comments at specific places you have to move the caret either upwards (instead of downwards which happens if you press enter) or click with the mouse so that the caret doesn't go to the line below the closing brace. Comments are also not inserted when the opening brace is less than two lines above.

            #region/#endregion for C++

            VS.NET introduced to possibility to outline portions of text in the code editor. That's a very useful feature wthat helps navigating through big bunches of code. But the outlined sections are not saved between sessions. VB and C# provide keywords to outline sections. In VB its '#Region' and '#End Region', in C# its '#region' and '#endregion'. Only for C++ MS didn't provide such keywords (at least I haven't found them yet). With this tool you can now enable that feature for C++ too. To prevent compiler errors for those who have not installed this tool I used '//#region' and '//#endregion' as the keywords. With the comment lines before the compiler won't complain. Use those keywords like this:

            outlined sections

            Whenever you open a document with such keywords the tool will automatically create outlining sections. The section are also created when you type the '//#endregion' keyword and a matching '//#region' is found. As you can see, you can easily nest the sections. The code above would then look like this:

            outlined sections

            outlined sections

            This function can't be deactivated. If you don't want it, simply don't use those keywords :)

            Search the web

            These two small addons perform a simple web site search either in the google groups or on CP. Select a piece of text in the code editor, right click to pop up the menu and then select where to search for the selected text. That's all. The search results will be opened inside VS.NET.

            right click menu

            Install

            To install the tools, just double-click the *.msi file and follow the instructions. If the tools are not automatically activated the next time you start the IDE, then please activate them under Tools->Add-In Manager. Make sure you select both the addin and the box 'startup'.

            All additional files needed for the tools are also packed in the installer, including Doxygen and the dot files. So you don't have to grab them separately from the web.

            Source

            Full source code is provided with these tools. The addin is written in VB.NET cause first there was just one simple tool that I wanted immediately - and VB is good enough for that. Then the tool grew and I added more functions. So the code is surely not the best example for good programming (no plan, no structure -> chaos). But maybe it might still be of interest for those who want to write their own addins. It shows a way to create submenus and how to add a toolbar.

            Revision History

            24.06.03
            • fixed bug in Doxygen part: the path to the binaries weren't enclosed in ""
            • made necessary changes to make the addin work with VS.NET2003 (projectitems are now recursive!)
            • updated the Doxygen binaries to the newest version
            • the dialogs are now centered to the IDE
            18.04.03
            • fixed some bugs in the }EndOf function
            • added template files for doxygen comments
            • fixed bug in the graph functions if the solution contained "misc" files
            • Doxygen 1.3 is now included
            • removed the toolbar - it slowed the editor down
            • for most commands disabled the check for project type (C++, C#, VB, ...) - if you use a function for a project type for what it isn't designed it just won't work...
            04.10.02
            • enabled }EndOf and the solution statistics also for C# projects
            21.9.02
            • fixed a bug in the }EndOf tool
            • fixed bug where Doxygen couldn't be started when a file was in the Solution->Misc folder
            • added possibility to run Doxygen for single projects (right click menu in solution explorer)
            • included newest Doxygen and Dot version
            • added a proper uninstaller. The uninstaller now deletes all added commands.
            7.9.02
            • fixed a bug reported by Darren Schroeder
            8.8.02
            • removed forgotten test code which caused annoying behaviour
            • made sure that for WinHelp output (Doxygen) also html output is selected
            10.8.02
            • fixed a bug reported by Jeff Combs: now the addin is only loaded when the IDE is started (the IDE is NOT started when devenv is called with /build, /clean or /deploy command line switches!)
            12.8.02
            • Run Doxygen now includes not only project directories but all directories of the project files.
            • The Toolbar can now be altered and the altered state is saved by the IDE
            • Uninstalling now works better: the toolbar is gone after the second start of the IDE after uninstalling without modifying the source.
            posted @ 2007-08-27 01:19 true 閱讀(659) | 評論 (1)編輯 收藏

            開源數據庫概覽

            開源世界真是太奇妙了,雖然不排除卑鄙無恥的直接盜用并貫為自己的產品,但開源可以無私到隨便你怎樣用。

            接觸開源有很長的一段時間了,先是學習別人的,然后還參與了開源,在sf.net上,我主持和參與了數個開源項目,當然,都不是大型的項目,只是嘗試一下。

            我所關注的開源項目方面很多,每方面都有很多優秀的作品,我將會在接下來的系列隨筆中介紹,這次介紹數據庫。

            這個星球上的數據庫實在不勝枚舉,這里只列一些我接觸過的常見的。

            可以稍微夸張點說,有交互的應用,起碼得用一下數據保存,即便是自定義結構的數據保存,還是最常見的INI、XML等,都可以算是“數據庫”,真正點的,如DBase系列、FoxBase、FoxPro、MSAccess、InterBase、MS SQL Server、Oracle、DB2等,這些是商業化的數據庫,前面幾個只能算是數據庫,后面幾個是RMDBS(關系型數據庫管理系統)。

            對應商業化的,有開源的:SQLite、SimpleSQLBerkely DBMinosse、Firebird( 前身是是Borland公司的InterBase)、PostgreSQL、MySQL等。

            SQLite:大家可以看我的SQLite系列隨筆,C編寫的,可以跨操作平臺,支持大部分ANSI SQL 92,它是嵌入式的輕量級關系形數據庫引擎,只需要一個DLL,體積為250k,數據庫也只是一個文件,零配置,便可工作。既然開源,你甚至可以把它嵌入你的程序中。核心開發人員只有一個,最近加入了另外一個,也就是2個人而已,實在佩服,目前發展到3.1.0,相當高效穩定,有開源驅動在sourceforge.net上有其ADO.NET Data Provider for SQLite :https://sourceforge.net/projects/adodotnetsqlite/ 。

            SimpleSQL:相對SQLite要大幾倍,但也是輕量級的,功能稍微強大一點,C++編寫,有OLE、Java等版本。

            Berkely DB:C++編寫的大型關系型數據庫系統,還額外地支持XML(把XML當成數據庫),號稱2百萬的安裝量,MySQL也只不過號稱5百萬安裝量而已,跨平臺。

            Minosse:純C#編寫的大型關系型數據庫系統,理想是超越MS SQL Server!最新版本:0.2.0,真難得,純Java寫的看得多了,純C#的,不是移植別人的,還是第一個,佩服作者:包含C/S和嵌入式版本,并可跨越大部分平臺,因為它不用Windows的東西,可以在Mono下編譯。

            Firebird:這個東西太牛了,目前有1.5穩定版本已經擁有大量特性,完全支持ANSI SQL92、98等,一些超酷的特性讓人瘋狂(1.0特性、1.5特性,從這里開始研究),主要開發人員是一個俄羅斯人,目前開發隊伍已經擴大到近100人,有3種模式,單機獨立,典型C/S,超級服務器。2.0版本和3.0版本將在近期推出,看完其路線圖(2.0、3.0)你就會瘋掉。有.NET驅動,目前是1.7beta版。主要特性: 
                ◆A.C.I.D; 
                ◆MGA(任何版本的引擎都可以處理同一數據庫記錄); 
                ◆PSQL(存儲過程)超級強大,ms sql相對的太次,它啥都能在服務器端實現并推送到客戶端成為強大的報表,存儲過程; 
                ◆觸發器都可以在客戶端獲取監控追蹤; 
                ◆自動只讀模式; 
                ◆創新的事務保證絕對不會出錯; 
                ◆24*7運行中仍然可以隨時備份數據庫; 
                ◆統一觸發器:任何操作都可以讓某表唯一的觸發器來總控; 
                ◆大部分語言都可以寫plug-in,并直接在存儲過程中調用函數; 
                ◆c->c++,更加少的代碼但更加快的速度; 
                ◆3種運行模式,甚至可以嵌入式; 
                ◆主流語言都可以調用它; 
                ◆動態sql執行; 
                ◆事務保存點;

            PostgreSQL:POSTGRES數據庫的后開源版本,號稱擁有任何其他數據庫沒有的大量新特性,似乎目標是要做超大型的OO關系型數據庫系統,目前已經發展到8.0,有.NET驅動,中文官方網站有詳細介紹。

            MySQL:這個,不用說了吧?號稱全球最受歡迎的開源數據庫,但讓我奇怪的是,PostgreSQL都有簡體中文的支持:包括內核、管理工具、QA等等,在最新版本MySQL中,我卻沒有發現... ,有.NET驅動,其中MySQL Connector/Net就是原來在sf.net上的ByteFX.Data項目,作者已經加入了MySQL團隊,參看《感慨 20 之開源的前途/錢圖?(1數據庫)》。
                
                網友評論
            RunEverywhere:   純Java寫的數據庫- -
              
              
              
              純Java數據庫包括:
              Informix, Cloudscape(也就是Apache Derby數據庫),JDataStore(Borland公司),HSQLDB, db4o, PointBase(Oracle創始人開發),
              
              Berkeley DB Java Edition 2.0 開源數據庫等等。誰有證據證明Oracle和DB2中Java使用的比例請告知。只知Oracle和DB2中有大量的.class文件,但不知是否有C/C++開發的部分,畢竟java也能編譯成.exe和.dll文件。
              
              Oracle數據庫(使用了Java開發,但不知是否是純Java)
              www.oracle.com
              
              
              DB2數據庫(使用了Java開發,但不知是否是純Java):
              www-306.ibm.com/software/data/db2/
              
              Informix數據庫
              
              IBM 在 2001 年七月初購併 Informix,將Informix 轉換為以Java 語言開發的環境之外,並採納 Informix
              的資料複製功能,提升 DB2 災難復原與資料複製的能力
              IBM 每年投資十億美元於資料庫管理軟體的研發工作,致力於強化資訊管理軟體解決方案的技術優勢與產品效能,去 ( 2003 ) 年並取得超過
              
              230 項相關專利權;又於日前捐出價值超過八千五百萬美元的 Java 資料庫軟體 Cloudscape 給 Apache
              
              
              http://www.ibm.com/news/tw/2004/11/tw_zh_20041119_linux.html
              Apache Derby 是一種用 100% 純 Java 編寫的關系數據庫。該項目最初被稱作 Cloudscape™,IBM 于 2004 年 8 月將它捐獻給了 Apache 基金組織
              http://www-128.ibm.com/developerworks/cn/db2/library/techarticles/dm-0505gibson/?ca=dwcn-newsletter-db2
              
              
              Cloudscape 開源數據庫
              
              於日前捐出價值超過八千五百萬美元的 Java 資料庫軟體 Cloudscape 給 Apache
              
              http://www.ibm.com/news/tw/2004/11/tw_zh_20041119_linux.html
              
              
              
              JDataStore數據庫
              
              Borland公司出品:
              www.borland.com/us/products/jdatastore/
              
              
              HSQLDB開源數據庫
              
              http://hsqldb.sf.net
              
              
              
              Berkeley DB Java Edition 2.0 開源數據庫
              
              http://www.sleepycat.com/
              
              
              db4o開源數據庫
              www.db4o.com/
              
              
              
              
              
              
              還有一些Java數據庫:
              
              在全球最大的java開發者雜志上的一份對最受歡迎的Java數據庫的調查:
              
              Best Enterprise Database:
              
               No Nominee
               Berkeley DB Java Edition Sleepycat Software
               Birdstep RDM Embedded 7.1 Birdstep Technology
               Daffodil DB Daffodil Software Ltd.
               db4o db4objects
               EAC MySQL Cluster Emic Networks
               HSQLDB HSQLDB Development Team
               IBM DB2 Universal Database IBM
               IBM Informix IDS v10 IBM
               JDataStore 7 High Availability Edition Borland Software
               ObjectDB for Java/JDO ObjectDB
               Oracle Database 10g Oracle Corporation
               Oracle Database Lite 10g Oracle Corporation
               PointBase Embedded PointBase / DataMirror Corp.
               Sybase Adaptive Server Enterprise (ASE) Sybase, Inc.
              
              
              http://jdj.sys-con.com/general/readerschoice.htm
              
              http://nuclearjava.blogchina.com/2006316.html (2005.06.26)

            posted @ 2007-08-20 12:13 true 閱讀(1098) | 評論 (0)編輯 收藏

            僅列出標題
            共15頁: First 7 8 9 10 11 12 13 14 15 
            久久婷婷五月综合成人D啪| 久久婷婷色综合一区二区| 99热精品久久只有精品| 久久午夜综合久久| 久久亚洲美女精品国产精品| 99久久综合狠狠综合久久止| 久久久久国产一级毛片高清板| 午夜精品久久久内射近拍高清| 蜜臀av性久久久久蜜臀aⅴ| 国产精品成人99久久久久| 国产成人精品综合久久久 | 亚洲精品蜜桃久久久久久| 久久Av无码精品人妻系列| 欧美日韩精品久久久免费观看| 亚洲国产精品无码久久一区二区 | 精品久久久久久国产免费了| 免费无码国产欧美久久18| 97超级碰碰碰碰久久久久| 久久久久久精品久久久久| 中文字幕亚洲综合久久2| 亚洲中文久久精品无码ww16 | 色婷婷综合久久久久中文| 久久久久人妻一区精品果冻| 99久久精品国产麻豆| 久久精品国产亚洲AV不卡| 久久精品国产清自在天天线| 成人综合伊人五月婷久久| 人妻少妇久久中文字幕一区二区| 性做久久久久久久久久久| 久久久精品日本一区二区三区| AAA级久久久精品无码片| 亚洲αv久久久噜噜噜噜噜| 久久久久高潮综合影院| 久久久久亚洲国产| 久久人人爽人人人人爽AV| 色播久久人人爽人人爽人人片aV | 色综合久久久久综合99| 久久精品国产欧美日韩| 久久综合视频网站| 亚洲精品乱码久久久久久蜜桃| 亚洲?V乱码久久精品蜜桃 |