exec sql include sqlca;到你的文件的包含段裏.這樣做將會定義一個結構和一個象下面一樣名爲 sqlca 的變量:
struct sqlca { char sqlcaid[8]; long sqlabc; long sqlcode; struct { int sqlerrml; char sqlerrmc[70]; } sqlerrm; char sqlerrp[8]; long sqlerrd[6]; /* 0: empty */ /* 1: OID of processed tuple if applicable */ /* 2: number of rows processed in an INSERT, UPDATE */ /* or DELETE statement */ /* 3: empty */ /* 4: empty */ /* 5: empty */ char sqlwarn[8]; /* 0: set to 'W' if at least one other is 'W' */ /* 1: if 'W' at least one character string */ /* value was truncated when it was */ /* stored into a host variable. */ /* 2: empty */ /* 3: empty */ /* 4: empty */ /* 5: empty */ /* 6: empty */ /* 7: empty */ char sqlext[8]; } sqlca;如果最後一個SQL 語句發生了錯誤,那麼 sqlca.sqlcode 將是非零值.如果 sqlca.sqlcode 小於 0 那麼就是發生了某種嚴重的錯誤,象數據庫定義與查詢定義不一致等.如果大於 0 則是通常的錯誤,象表不包括所要求的行等.
sqlca.sqlerrm.sqlerrmc 將包含一個字符串描述該錯誤.該字符串以源文件的行號結尾。
- -12, Out of memory in line %d.
- 通常不出現這個錯誤。這是你的虛擬內存耗盡的標誌。
- -200, Unsupported type %s on line %d.
- 通常不出現這個錯誤.這表明預編譯器生成了一些庫(函數)不認得的東西.可能你運行的預編譯器和當前庫不兼容.
- -201, Too many arguments line %d.
- 這意味着 Postgres 返回了比我們的匹配變量更多的參數.可能你漏了幾個INTO :var1,:var2-列表裏的宿主變量.
- -202, Too few arguments line %d.
- 這意味着 Postgres 返回了比我們的對應宿主變量要少的參數.可能你多輸入了幾個INTO :var1,:var2-列表裏的宿主變量.
- -203, Too many matches line %d.
- 這意味着查詢返回了多個行,但你聲明的變量不是數組.你執行的 SELECT 可能不是唯一的.
- -204, Not correctly formatted int type: %s line %d.
- 這意味着宿主變量是一個 int 類型並且 Postgres 數據庫裏的字段是另一種類型,包含着一個不能轉換成一個 int 類型的數值.庫(函數)使用 strtol 做此類轉換.
- -205, Not correctly formatted unsigned type: %s line %d.
- 這意味着宿主變量是一個 unsigned int(無符號整數)類型而Postgres 數據庫裏的字段是另外一種類型並且包含一個不能轉換成unsigned int 的數值.庫(函數)使用 strtoul 做這類轉換.
- -206, Not correctly formatted floating point type: %s line %d.
- 這意味着宿主變量是一個 float (浮點)類型而 Postgres 數據庫裏的字段是另外一種類型並且包含一個不能轉換成float 的數值.庫(函數)使用 strtod 做這類轉換.
- -207, Unable to convert %s to bool on line %d.
- 這意味着宿主變量是一個 bool (布爾)類型,而 Postgres 數據庫裏的字段值既不是 't' 也不是 'f'。
- -208, Empty query line %d.
- Postgres 返回 PGRES_EMPTY_QUERY,可能的原因是該查詢實際上是空的。
- -220, No such connection %s in line %d.
- 程序試圖訪問一個不存在的聯接。
- -221, Not connected in line %d.
- 程序試圖訪問一個存在的,但是沒有打開的聯接。
- -230, Invalid statement name %s in line %d.
- 你試圖使用的語句還沒準備好。
- -400, Postgres error: %s line %d.
- 某種 Postgres 錯誤。該消息包含來自 Postgres 後端的信息。
- -401, Error in transaction processing line %d.
- Postgres 給我們的信號,表明我們無法開始,提交或者回卷該事務。
- -402, connect: could not open database %s.
- 與數據庫的聯接無法工作。
- 100, Data not found line %d.
- 這是一個"正常的"錯誤,告訴你你正在查詢的東西找不到或者我們已經越過了遊標的範圍。