線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2714
推到 Plurk!
推到 Facebook!

大量資料 update與insert,Tquery 錯誤.

答題得分者是:inungh
viya
一般會員


發表:16
回覆:19
積分:7
註冊:2008-09-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2012-04-10 12:57:54 IP:202.3.xxx.xxx 訂閱
各位好:
手邊有一隻程式,需用到 TQuery進行大量資料 update與insert
測試發現,竟然會出現連sql.savetofile都不行都狀況.
當我存空白檔案時,又ok了

close;
sql.clear;
sql.savetofile('c:\XXXX.sql');
(這樣存檔是成功的,但中間加了sql command 又失敗,文字並沒有過長的情況,總行數在100行以內)

推測可能是跟 TQuery進行大量資料 update與insert有關

想請教版上各位前輩,是否有方法,能夠將記憶體 release出來.
或是有其他作法??

感謝各位..
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2012-04-10 13:32:10 IP:59.120.xxx.xxx 未訂閱
有試過將SQL內容導出來再存過嗎?(TStringList、TMemo)

===================引 用 viya 文 章===================
各位好:
手邊有一隻程式,需用到TQuery進行大量資料 update與insert
測試發現,竟然會出現連sql.savetofile都不行都狀況.
當我存空白檔案時,又ok了

close;
sql.clear;
sql.savetofile('c:\XXXX.sql');
(這樣存檔是成功的,但中間加了sql command 又失敗,文字並沒有過長的情況,總行數在100行以內)

推測可能是跟TQuery進行大量資料 update與insert有關

想請教版上各位前輩,是否有方法,能夠將記憶體 release出來.
或是有其他作法??

感謝各位..
fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#3 引用回覆 回覆 發表時間:2012-04-10 14:31:09 IP:202.3.xxx.xxx 訂閱
感謝您的回覆,我剛測試寫入memo裡,又出現其他錯誤訊息
「access violation at address 00402911」

close;
sql.clear
sql.add('select * from ' 變數名稱 ' ') --> 程式trace到這一行出錯

真的太奇怪了,我只是做 sql.add的動作,變數也有值. (showmessage有show出來)


===================引 用 老大仔 文 章===================
有試過將SQL內容導出來再存過嗎?(TStringList、TMemo)

===================引 用 viya 文 章===================
各位好:
手邊有一隻程式,需用到TQuery進行大量資料 update與insert
測試發現,竟然會出現連sql.savetofile都不行都狀況.
當我存空白檔案時,又ok了

close;
sql.clear;
sql.savetofile('c:\XXXX.sql');
(這樣存檔是成功的,但中間加了sql command 又失敗,文字並沒有過長的情況,總行數在100行以內)

推測可能是跟TQuery進行大量資料 update與insert有關

想請教版上各位前輩,是否有方法,能夠將記憶體 release出來.
或是有其他作法??

感謝各位..
fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2012-04-10 15:49:15 IP:202.3.xxx.xxx 訂閱
我測試,不論是否導入Tmemo,都會出現錯誤訊息

1.會跳出access violation
2. sql command 字元被截斷,出現亂碼
3.sql command 跳行

我測試將該段程式碼 搬到另一個程式去執行,一切很順利沒問題.(不做update 與insert)
應該記憶體的影響.請問有方法能夠將記憶體 release出來嗎???

===================引 用 老大仔 文 章===================
有試過將SQL內容導出來再存過嗎?(TStringList、TMemo)

===================引 用 viya 文 章===================
各位好:
手邊有一隻程式,需用到TQuery進行大量資料 update與insert
測試發現,竟然會出現連sql.savetofile都不行都狀況.
當我存空白檔案時,又ok了

close;
sql.clear;
sql.savetofile('c:\XXXX.sql');
(這樣存檔是成功的,但中間加了sql command 又失敗,文字並沒有過長的情況,總行數在100行以內)

推測可能是跟TQuery進行大量資料 update與insert有關

想請教版上各位前輩,是否有方法,能夠將記憶體 release出來.
或是有其他作法??

感謝各位..
inungh
初階會員


發表:0
回覆:27
積分:25
註冊:2011-06-19

發送簡訊給我
#5 引用回覆 回覆 發表時間:2012-04-16 03:46:35 IP:70.81.xxx.xxx 訂閱
 Can you please post your SQL code here?

inungh
------
Inung Huang
fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#6 引用回覆 回覆 發表時間:2012-04-16 09:34:46 IP:211.21.xxx.xxx 訂閱
inungh 您好:
我把sql 整個copy到另一個程式執行,測試可執行,savetofile 也ok。
推測與sql應該無關。而且這段sql,在前幾個月是可以執行的,

不曉得是不是這幾個月,資料量變大,加上程式有做大量資料的update與insert
(暫存檔,檔案均在oracle中)
目前測試
1.dbsession.close
2 databse.connected:=false
sql.add仍然會出現access violation.


===================引 用 inungh 文 章===================
Can you please post your SQL code here?

inungh
編輯記錄
fivker 重新編輯於 2012-04-15 19:41:13, 註解 無‧
inungh
初階會員


發表:0
回覆:27
積分:25
註冊:2011-06-19

發送簡訊給我
#7 引用回覆 回覆 發表時間:2012-04-16 09:53:37 IP:70.81.xxx.xxx 訂閱
 then you need make sure 
變數名稱 exists in your database.

access violation means Delphi can not find the object.


inung
------
Inung Huang
fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#8 引用回覆 回覆 發表時間:2012-04-16 14:35:59 IP:220.128.xxx.xxx 訂閱
您好

我確定變數名稱是存在,也有值的。

我的問題,除了執行到有變數的地方,發生error外。

執行到一般的sql.add也會出錯,更奇怪的是
同樣的sql command

sql.add('select * ');
sql.add('from ( '); //trace這一句出現access violation
以下省略...

我把藍色字串copy取代紅色字串,就可以run了.(真的是哭笑不得)
可是問題依舊無解.其他程式片段仍是出現access violation
而且都是出現在 sql.add(' ’) 時,發生錯誤.
如果是在open 或是execsql時出錯,都還可以解釋....

所以才會懷疑是不是占用太多資源,造成query問題。
煩請各位前輩協助,是否有其他的辦法,可以記憶體release出來。


===================引 用 inungh 文 章===================
then you need make sure
變數名稱 exists in your database.

access violation means Delphi can not find the object.


inung
inungh
初階會員


發表:0
回覆:27
積分:25
註冊:2011-06-19

發送簡訊給我
#9 引用回覆 回覆 發表時間:2012-04-18 06:08:13 IP:70.81.xxx.xxx 訂閱
It looks like your SQL statement get cut by Delphi..
Please make sure your SQL does not get cut in the middle of word.


inung



------
Inung Huang
inungh
初階會員


發表:0
回覆:27
積分:25
註冊:2011-06-19

發送簡訊給我
#10 引用回覆 回覆 發表時間:2012-04-18 11:36:06 IP:70.81.xxx.xxx 訂閱
1. Since it deos not fail when you exec SQL or open the query, it is Delphi side issue, not SQL side.
2. You mentioned that sql.add('from ( ');
以下省略...
union all
sql.add('select * ');
變數名稱 exists in your database.

access violation means Delphi can not find the object.


inung
------
Inung Huang
fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#11 引用回覆 回覆 發表時間:2012-04-18 15:55:42 IP:220.128.xxx.xxx 訂閱
感謝 inungh的回覆:

我確定每一行都不超過255字元,總行數不超過100行。

我試過
將一整段的sql command移至新的程式執行。一切都很順利,sql.add都ok。(savefile 也ok)
但回到舊程式,還是會出現錯誤。


===================引 用 inungh 文 章===================
1. Since it deos not fail when you exec SQL or open the query, it is Delphi side issue, not SQL side.
2.You mentioned that"sql command字元被截斷,出現亂碼", it lloks like your SQL statment get cut off by Delphi.
You can re arrange SQL to make sure the total lenth is less than 255 characters per line and make sure has space between 2 lines.

Good luck,

inung

fivker
一般會員


發表:24
回覆:38
積分:12
註冊:2006-12-05

發送簡訊給我
#12 引用回覆 回覆 發表時間:2012-04-19 16:24:19 IP:220.128.xxx.xxx 訂閱
感謝大家的指導.. ^^
終於找到原因了
因為procedure 行數大多 (大約2900行)
我把procedure 拆開好幾個部份,就可以跑了.

試了好久,程式在delphi 5上,compile都沒有錯誤.
改在delphi 2009上 compile,出現error訊息 shorter procedure





===================引 用 fivker 文 章===================
感謝 inungh的回覆:

我確定每一行都不超過255字元,總行數不超過100行。

我試過
將一整段的sql command移至新的程式執行。一切都很順利,sql.add都ok。(savefile 也ok)
但回到舊程式,還是會出現錯誤。


===================引 用 inungh 文 章===================
1. Since it deos not fail when you exec SQL or open the query, it is Delphi side issue, not SQL side.
2.You mentioned that"sql command字元被截斷,出現亂碼", it lloks like your SQL statment get cut off by Delphi.
You can re arrange SQL to make sure the total lenth is less than 255 characters per line and make sure has space between 2 lines.

Good luck,

inung

編輯記錄
fivker 重新編輯於 2012-04-19 02:55:48, 註解 無‧
系統時間:2024-04-26 21:35:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!