文字檔格式 (文字檔驅動程式)

ODBC Text 驅動程式同時支援分隔和固定寬度的文字檔。 文字檔是由選擇性的標題行和零或多個文字行所組成。

雖然標題行使用與文字檔中其他行相同的格式,但 ODBC Text 驅動程式會將標題行項目解譯為資料行名稱,而非資料。

分隔的文字行包含一或多個以分隔符號分隔的資料值,包括逗號、定位點或自訂分隔符號。 整個檔案必須使用相同的分隔符號。 Null 資料值由資料列中兩個分隔符號所表示,分隔符號之間沒有資料。 分隔文字行內的字元字串可括在雙引號符號 ("") 內。 分隔值前後不可有空白。

固定寬度文字行內每個資料項目的寬度係由結構描述所指定。 Null 資料值會以空白表示。

資料表最多限制為 255 個欄位。 欄位名稱限制為 64 個字元,欄位寬度限制則為 32,766 個字元。 記錄限制為 65,000 個位元組。

文字檔只能由單一使用者開啟。 不支援多名使用者。

下列為程式設計人員撰寫的文法會定義 ODBC 文字驅動程式可讀取的文字檔格式:

格式 表示法
非斜體 必須輸入的字元,如下所示
斜體 在文法中其他地方定義的引數
括弧 ([]) 選擇性項目
大括號 ({}) 互斥選項的清單
分隔號 (|) 分隔互斥選項
省略符號 (...) 可以重複一或多次的項目

文字檔的格式為:

text-file ::=  
   [delimited-header-line] [delimited-text-line]... end-of-file |  
   [fixed-width-header-line] [fixed-width-text-line]... end-of-file  
delimited-header-line ::= delimited-text-line  
delimited-text-line ::=  
   blank-line |  
   delimited-data [delimiter delimited-data]... end-of-line  
fixed-width-header-line ::= fixed-width-text-line  
fixed-width-text-line ::=  
   blank-line |  
   fixed-width-data [fixed-width-data]... end-of-line  
end-of-file ::= <EOF>  
blank-line ::= end-of-line  
delimited-data ::= delimited-string | number | date | delimited-null  
fixed-width-data ::= fixed-width-string | number | date | fixed-width-null  

注意

固定寬度文字檔中每個資料行的寬度係由 Schema.ini 檔案所指定。

  
      end-of-line ::= <CR> | <LF> | <CR><LF>  
delimited-string ::= unquoted-string | quoted-stringunquoted-string ::= [character | digit] [character | digit | quote-character]...  
quoted-string ::=  
   quote-character  
   [character | digit | delimiter | end-of-line | embedded-quoted-string]...  
   quote-characterembedded-quoted-string ::=   quote-characterquote-character  
   [character | digit | delimiter | end-of-line]  
   quote-characterquote-characterfixed-width-string ::= [character | digit | delimiter | quote-character] ...  
character ::= any character except:  
   delimiterdigitend-of-fileend-of-linequote-characterdigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  
delimiter ::= , | <TAB> |   
custom-delimitercustom-delimiter ::= any character except:  
   end-of-fileend-of-linequote-character  

注意

自訂分隔文字檔的分隔符號由 Schema.ini 檔案指定。

quote-character ::= "  
number ::= exact-number | approximate-number  
exact-number ::= [+ | -] {unsigned-integer[.unsigned-integer] |  
   unsigned-integer. |  
   .unsigned-integer}  
approximate-number ::= exact-number{e | E}[+ | -]unsigned-integer  
unsigned-integer ::= {digit}...  
date ::=  
   mm date-separator dd date-separator yy |  
   mmm date-separator dd date-separator yy |  
   dd date-separator mmm date-separator yy |  
   yyyy date-separator mm date-separator dd |  
   yyyy date-separator mmm date-separator dd  
mm ::= digit [digit]  
dd ::= digit [digit]  
yy ::= digit digit  
yyyy ::= digit digit digit digit  
mmm ::= Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec  
date-separator ::= - | / | .  
delimited-null ::=  

注意

針對分隔的檔案,Null 字元會以兩個分隔符號之間沒有資料表示。

fixed-width-null ::= <SPACE>...  

注意

針對寬度固定的檔案,Null 字元會以空格表示。