- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
[摘自 水木清华站] T" p: f, N0 T- _1 j
Q- \3 }4 Y. Z$ J 7 ~ b7 t5 V8 f" m- c
对于SQL中的TEXT、IMAGE、MEMO字段的存取,可以采用下列程序:
3 H2 D7 i: Z, Z9 |BLOB字段的读取: & K1 S) I7 F" f" p! f: `
TBlobSTream* TemplateStream;
4 ^8 y. m' ^6 T* \ char* TempPlatePtr;
% Z- T% d2 n [6 K& O% ~8 `# o. y
0 @' o6 I. \- b Q3 _; i TemplateStream=new TBlobStream((TBlobField*)WebQuery->FieldByName
+ e; a7 R0 X; ~! A: D7 h ("SearchTem"),bmReadWrite);
2 K- s% H# N L6 Z& ~2 b TemplatePtr= new char[TemplateStream->Size];
) t/ L4 o& t; O" x2 P4 j TemplateStream->Read(TemplatePtr, TemplateStream->Size); 6 j3 X. L. c3 P/ ?9 R4 h9 e
4 {5 h% Q6 Q& W! j2 ^$ y$ _
BLOB字段的写入: 8 n; ^- I3 e; r" R0 y
TBlobSTream* TemplateStream;
3 d5 X' y0 {- E* }& W char* TempPlatePtr;
5 ?3 V, T8 E. X( n1 W5 r
" s, W' V/ ^- H6 B7 u' u; K TemplateStream=new TBlobStream((TBlobField*)WebQuery->FieldByName
4 @/ Y; w- H" |1 t# B ("SearchTem"),bmReadWrite);
G% Z5 W& e2 P( x TemplatePtr= new char[TemplateStream->Size];
5 V# I: U- O( W9 U! R TemplateStream->Write(TemplatePtr, TemplateStream->Size); 1 E: l$ O+ m# B3 l7 S
% K/ ~8 ]# \2 A! d/ Q9 P1 S1 o5 Y
________________________________________________________________
7 [, _4 r* [4 ` J补充: % W# `& k3 P' | j7 U
获得字段的大小用函数datalength
5 M5 U# ^2 o5 ~1 K9 P1 K0 g* N 3 L' d8 N: N# L
SQL Server端要作一点设置: ) S5 \8 [" ?, h: y
By default, WRITETEXT is a nonlogged operation. This means that
8 L* U- J# b7 u" W8 x8 otext or image data is not logged when it is written into the database. ' _+ m+ X; k2 `3 Q9 Z
To use WRITETEXT in its default, nonlogged state,
7 L" f3 V1 W% |5 _//注意!!
+ k# T _! e! r# a8 D+ I$ hthe system administrator must use the sp_dboption system stored
. `1 {* K' b1 S' a) R# `8 tprocedure to set select into/bulkcopy,
1 K: _! K" `, a' h9 s" U O) U// 2 p1 A @, S3 ^9 m1 X/ A4 j
which allows nonlogged data to be inserted.
/ K9 f; S$ ^: x' `1 y' ^ : K+ q* R, W4 O# W5 U7 z
做了试验,直接写SQL语句好象不行. + @- r- r1 k o2 W7 W# S$ s
____________________________________________________________________
) t1 K; w5 n' ]+ `% D4 d5 w 一些注意事项和一个例子
# s* D! J6 [9 R8 B u* a在写入时:
9 Q$ q; W& N- o+ f5 g4 @(1)如果使用的是TTable,则要将其ReadOnly属性先置为false,然后调用Edit函数;
6 [! y7 T3 n% [(2)如果使用的是TQuery,则要将其RequestLive属性先置为true,然后调用Edit函数; ; a- R# E8 a$ q1 W
使得TTable(TQuery)是可写的.
3 Q X: L$ j- G# V + r F# ?7 m' l7 b
下面是一个使用TQuery往content表(主键file_id)中插入一条记录的例子,
% y$ @! `# C( o" Y( z8 {5 ^script为一个BLOB字段:
5 c6 w7 {9 a g, X4 U7 V* }' V TBlobStream *pScriptStream; - q5 ~+ `; Y; b3 }1 V
//插入一条记录 2 ~& j2 I, U4 N. }) i. y
strSQL1="insert into content(file_id,script,key_image) values('";
% \/ j& q8 Y7 O strSQL1=strSQL1+m_szFileID+"',null,null)"; 2 o: U5 _* d% ]" M8 T; G( @3 ?
dmStoryEditor->qryExec->SQL->Clear(); \8 w1 J3 n% I( g( J: b9 E. u) P
dmStoryEditor->qryExec->SQL->Add(strSQL1); 9 }( | ~6 l* e) d, ~/ O7 n
dmStoryEditor->qryExec->ExecSQL(); % N/ @6 w: F! ?1 e; a% h. r
dmStoryEditor->qryExec->Close();
: V' }) k7 n3 @$ I* S/ h! K% [ //整理要写入的Blob数据 , r J* C7 ^" p- n. M0 P* O
LockMemories(NewsScript); ' Q/ i; q4 v3 H0 T
NewsScript.GetEdition(NewsScript.m_ScriptHead.byteEditionNum);
8 U, |4 D! J% U+ g4 Q o NewsScript.m_pScript=(BYTE *)GlobalLock(NewsScript.m_hScript);
) O. ?: c# g7 k* n: v6 M# o- [& l if(NewsScript.m_pScript!=NULL)
0 r1 `- ?8 H8 `( S( h { ) M6 o2 y2 [8 R- }9 O
//再将刚插入的记录读出来,使该Query与该条记录关联
. N- b4 y7 F$ s; m( V3 M9 I strSQL1="select file_id,script from content where file_id='"+ ! R- z( B; X; q: W Q! k" E$ B2 l
m_szFileID+"'"; % b+ K e. W: v) U4 V) o( r! ~1 s+ M
//允许该Query写
8 c2 v( s4 U' @. Q dmStoryEditor->qryExec->RequestLive=true;
. G6 C/ x2 Y* J% Y* v dmStoryEditor->qryExec->SQL->Clear(); 6 f9 {6 A0 A, W3 W4 l; E7 |; G/ I
dmStoryEditor->qryExec->SQL->Add(strSQL1);
7 x2 [/ t! J; d1 D5 S! f+ ~ dmStoryEditor->qryExec->Open(); 9 E/ ^) P6 H f( j. g1 b( z1 S
dmStoryEditor->qryExec->First();
" m& p ], J, B0 u) ^& R; r4 O //将该Query置为可写
! a! Q- X6 {/ j dmStoryEditor->qryExec->Edit(); * D& ^. ], M- a9 E% I# s4 z4 y
pScriptStream=new TBlobStream((TBlobField*)dmStoryEditor->
" N& [ m7 C0 i qryExec->FieldByName("script"),bmReadWrite);
5 i( Q4 i" c1 ^# D- Y$ r8 \ pScriptStream->Write(NewsScript.m_pScript, 6 H& e+ z9 @# K$ @: m0 x
NewsScript.m_lScriptRealSize);
6 h# s3 E4 f$ r, K6 C dmStoryEditor->qryExec-> ost(); 5 i+ Q+ a5 ~. g7 ]) q! i7 ~5 [% N
dmStoryEditor->qryExec->RequestLive=false; ' t) }( E) h. t
delete pScriptStream;
9 y- E/ u, u1 u }
0 a6 j* l- u E GlobalUnlock(NewsScript.m_hScript);
# Z7 \# n/ _( d I UnLockMemories(NewsScript); |
zan
|