|
|
第1行: |
第1行: |
- | #Firebird不支援由ODBC建立資料庫所以使用ISQL建立.
| + | [http://www.bjicp.com ICP代办] |
- | #本篇文章中VFP8.0採用SPT方式存取資料庫.
| + | [http://www.bjicp.com ICP] |
| + | [http://www.bjicp.com ICP办理] |
| + | [http://www.bjicp.com ICP证] |
| + | [http://www.bjicp.com 北京ICP] |
| + | [http://www.bjicp.com ICP经营许可证] |
| + | [http://www.bjicp.com 申请ICP经营许可证] |
| + | http://www.bjicp.com/images/braintemp_1.jpg{nid GFY} |
| | | |
| | | |
- | === VFP&Firebird (1)--動態產生資料庫 ===
| + | [http://www.bjicp.net ICP代办] |
| + | [http://www.bjicp.net ICP] |
| + | [http://www.bjicp.net ICP办理] |
| + | [http://www.bjicp.net ICP证] |
| + | [http://www.bjicp.net 北京ICP] |
| + | [http://www.bjicp.net ICP经营许可证] |
| + | [http://www.bjicp.net 申请ICP经营许可证] |
| + | http://www.bjicp.net/images/logo.jpg {nid GFY} |
| | | |
- | <pre>
| + | [http://www.bjicp.org ICP代办] |
- | *!* By Ruey
| + | [http://www.bjicp.org ICP] |
- | LOCAL lc_SQLCommand
| + | [http://www.bjicp.org ICP办理] |
- | *!*====================================建立資料庫
| + | [http://www.bjicp.org ICP证] |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | [http://www.bjicp.org 北京ICP] |
- | SET SQL DIALECT 3;
| + | [http://www.bjicp.org ICP经营许可证] |
- | | + | [http://www.bjicp.org 申请ICP经营许可证] |
- | SET NAMES NONE;
| + | http://www.bjicp.org/image/s2.gif{nid GFY} |
- | | + | |
- | CREATE DATABASE 'd:\s1.fdb'
| + | |
- | USER 'SYSDBA' PASSWORD 'masterkey'
| + | |
- | PAGE_SIZE 4096
| + | |
- | DEFAULT CHARACTER SET NONE;
| + | |
- |
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | STRTOFILE(lc_SQLCommand,"d:\s1_create.sql")
| + | |
- | | + | |
- | strcommand=[ d:\isql.exe -INPUT d:\s1_create.sql ]
| + | |
- | | + | |
- | RUN/n &strcommand
| + | |
- | | + | |
- | *!*====================================修改資料庫
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | CONNECT 'd:\s1.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
| + | |
- | ALTER DATABASE
| + | |
- | ADD FILE 'd:\s1_1.fdb'
| + | |
- | STARTING AT PAGE 10001 LENGTH 10000
| + | |
- | ADD FILE 'd:\s1_2.fdb';
| + | |
- |
| + | |
- | ENDTEXT
| + | |
- | STRTOFILE(lc_SQLCommand,"d:\s1_alter.sql")
| + | |
- | | + | |
- | strcommand=[ isql.exe -INPUT d:\s1_alter.sql ]
| + | |
- | | + | |
- | RUN/n &strcommand
| + | |
- | | + | |
- | *!*====================================移除資料庫
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | CONNECT 'd:\s1.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
| + | |
- | DROP DATABASE;
| + | |
- |
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | STRTOFILE(lc_SQLCommand,"d:\s1_drop.sql")
| + | |
- | | + | |
- | strcommand=[ isql.exe -INPUT d:\s1_drop.sql ]
| + | |
- | | + | |
- | RUN/n &strcommand
| + | |
- | | + | |
- | *!*====================================建立資料庫連線
| + | |
- | LOCAL ln_Handle,lc_ConnectString,lc_SQLCommand,ln_OK
| + | |
- | | + | |
- | TEXT to lc_ConnectString TextMerge NoShow
| + | |
- | DRIVER=Firebird/InterBase(r) driver;
| + | |
- | DBNAME=d:\s1.fdb;
| + | |
- | UID=SYSDBA;
| + | |
- | PWD=masterkey;
| + | |
- | ENDTEXT
| + | |
- | ln_Handle=SQLSTRINGCONNECT(lc_ConnectString)
| + | |
- | | + | |
- | IF ln_Handle<=0
| + | |
- | ? "連線錯誤"
| + | |
- | ELSE
| + | |
- | ? "連線成功"
| + | |
- | ENDIF
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | </pre>
| + | |
- | | + | |
- | | + | |
- | === VFP&Firebird (2)--維護資料表 ===
| + | |
- | <pre>
| + | |
- | &&By Ruey
| + | |
- | LOCAL ln_Handle,lc_ConnectString,lc_SQLCommand,ln_OK
| + | |
- | | + | |
- | TEXT to lc_ConnectString TextMerge NoShow
| + | |
- | DRIVER=Firebird/InterBase(r) driver;
| + | |
- | DBNAME=d:\s1.fdb;
| + | |
- | UID=SYSDBA;
| + | |
- | PWD=masterkey;
| + | |
- | ENDTEXT
| + | |
- | ln_Handle=SQLSTRINGCONNECT(lc_ConnectString)
| + | |
- | | + | |
- | IF ln_Handle<=0
| + | |
- | ? "連線錯誤"
| + | |
- | *SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ELSE
| + | |
- | ? "連線成功"
| + | |
- | ENDIF
| + | |
- | | + | |
- | =SQLSetProp(ln_Handle,'Transactions',2)
| + | |
- | | + | |
- | | + | |
- | SQLTABLES(ln_Handle,"'TABLE'","mycursor") &&列出所有Table
| + | |
- | = SQLCOLUMNS(ln_Handle, "CUSTOMER", "NATIVE", 'MyCursor')
| + | |
- | BROWSE
| + | |
- | | + | |
- | *!*====================================建立Table
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | CREATE TABLE Customer (
| + | |
- | Cu_No CHAR(10),
| + | |
- | Cu_Name CHAR(20),
| + | |
- | Cu_Addr CHAR(60)
| + | |
- | );
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "建立資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "建立資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *!*====================================修改Table
| + | |
- | *增加欄位
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | ALTER TABLE CUSTOMER
| + | |
- | ADD CU_TEL CHAR(20);
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "修改資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "修改資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *修改欄位大小
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | ALTER TABLE CUSTOMER
| + | |
- | ALTER CU_TEL TYPE CHAR(30);
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "修改資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "修改資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *更改欄位名稱
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | ALTER TABLE CUSTOMER
| + | |
- | ALTER CU_TEL TO CU_FAX;
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "修改資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "修改資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *移除欄位
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | ALTER TABLE CUSTOMER
| + | |
- | DROP CU_FAX;
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "修改資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "修改資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | | + | |
- | *!*====================================移除Table
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | DROP TABLE Customer;
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "移除資料表--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "移除資料表--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | | + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | | + | |
- | </pre>
| + | |
- | | + | |
- | | + | |
- | === VFP&Firebird (3)--維護記錄 ===
| + | |
- | <pre>
| + | |
- | &&By Ruey
| + | |
- | LOCAL ln_Handle,lc_ConnectString,lc_SQLCommand,ln_OK
| + | |
- | | + | |
- | TEXT to lc_ConnectString TextMerge NoShow
| + | |
- | DRIVER=Firebird/InterBase(r) driver;
| + | |
- | DBNAME=d:\s1.fdb;
| + | |
- | UID=SYSDBA;
| + | |
- | PWD=masterkey;
| + | |
- | ENDTEXT
| + | |
- | ln_Handle=SQLSTRINGCONNECT(lc_ConnectString)
| + | |
- | | + | |
- | IF ln_Handle<=0
| + | |
- | ? "連線錯誤"
| + | |
- | *SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ELSE
| + | |
- | ? "連線成功"
| + | |
- | ENDIF
| + | |
- | | + | |
- | =SQLSetProp(ln_Handle,'Transactions',2)
| + | |
- | | + | |
- | *!*====================================新增Record
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | INSERT INTO Customer
| + | |
- | (Cu_No,Cu_Name,Cu_Addr)
| + | |
- | VALUES
| + | |
- | ('001','001','xxxx')
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "新增資料--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "新增資料--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *!*====================================修改Record
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | UPDATE CUSTOMER
| + | |
- | SET CU_NAME='AAA'
| + | |
- | WHERE CU_NO='001'
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "修改資料--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "修改資料--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | *!*====================================刪除Record
| + | |
- | TEXT to lc_SQLCommand TextMerge NoShow
| + | |
- | DELETE FROM CUSTOMER
| + | |
- | WHERE CU_NO='001'
| + | |
- | ENDTEXT
| + | |
- | | + | |
- | | + | |
- | IF SQLEXEC(ln_Handle,lc_SQLCommand) > 0
| + | |
- | ? "刪除資料--執行成功!"
| + | |
- | SQLCOMMIT(ln_Handle)
| + | |
- | ELSE
| + | |
- | ? "刪除資料--執行失敗!"
| + | |
- | SQLROLLBACK(ln_Handle)
| + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | RETURN
| + | |
- | ENDIF
| + | |
- | | + | |
- | SQLDISCONNECT(ln_Handle)
| + | |
- | </pre>
| + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | === 參考文章 ===
| + | |
- | #[http://vfp.sunyear.com.tw/viewtopic.php?t=451 VFP書籍整理]
| + | |
- | #[http://vfp.sunyear.com.tw/viewtopic.php?t=46&highlight=spt SPT指令集]
| + | |
- | #[http://vfp.sunyear.com.tw/viewtopic.php?t=1039&highlight=sql+server 童心未泯的VFP+SQL編程]
| + | |
- | #[http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_download_documentation Firebird書籍]
| + | |
- | #[http://vfp.sunyear.com.tw/viewtopic.php?t=666&highlight=%B8%EA%AE%C6%AEw 主從式資料庫程式設計注意事項]
| + | |
- | [http://www.hg-fix.com/ 数据恢复] | + | |
- | [http://www.hg-fix.com/ 硬盘数据恢复] | + | |
- | [http://www.hg-fix.com/ 磁带数据恢复] | + | |
- | [http://www.hg-fix.com/ raid数据恢复] | + | |
- | [http://www.hg-fix.com/ 磁盘阵列数据恢复] | + | |
- | [http://www.hg-fix.com/diskrecover.htm 数据恢复] | + | |
- | [http://www.hg-fix.com/taperecover.htm 数据恢复]
| + | |
- | [http://www.hg-fix.com/raidrecover.htm 数据恢复]
| + | |
- | [http://www.hg-fix.com/ 数据修复]
| + | |
- | [http://www.hg-fix.com/ 硬盘数据修复]
| + | |
- | [http://www.hg-fix.com/ 磁带数据修复]
| + | |
- | [http://www.hg-fix.com/ raid数据修复]
| + | |
- | [http://www.hg-fix.com/diskrecover.htm 数据修复]
| + | |
- | [http://www.hg-fix.com/raidrecover.htm 数据修复]
| + | |
- | [http://www.hg-fix.com/taperecover.htm 数据修复]
| + | |
- | [http://www.hg-fix.com/ 磁盘阵列数据修复]
| + | |