怎么样把一篇文章存储到数据库中?

fenglaotou 2002-12-08 03:31:25
同题
...全文
507 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
twtxrjsojieke 2003-03-05
  • 打赏
  • 举报
回复
能不能给个源码
andyzq 2002-12-20
  • 打赏
  • 举报
回复
如果是要输入很长的内容,那么使用text类型的字段。
但是听说在pb里有限制,输入内容超过4000个字符时就输不进去了,就像varchar类型在pb里限制在255个字符一样,多于255就不行了。前两个星期就有这样一个帖子问使用text类型的字段的时候怎么突破4000个字节的限制,现在不知道解决了没有,你可以去看看。我自己还有试过把很长的文字存进去,所以不知道有没有这个限制,
如果你要输入的内容少于4000个字符我想是没有问题的。
bcbhj 2002-12-10
  • 打赏
  • 举报
回复
如果是要往一个表里添文本呢???而不是把已存在的文章存到数据库
如个人简历,要敲大段文字到数据库,怎么做来着??
888888888888 2002-12-09
  • 打赏
  • 举报
回复
做出来了吗?
dotnba 2002-12-08
  • 打赏
  • 举报
回复
:-)
andyzq 2002-12-08
  • 打赏
  • 举报
回复
更正: 是使用fileread()函数,有点像所以写错了. 呵呵!
如果你只保存一个文件,那么
ls_pathname = docname 就行了

sqlca.autocommit = true

li_value = GetFileOpenName("读取文件",docname, named, "jpg","*.jpg,*.jpg,")
if li_value <> 1 then return
ll_len_docname = len(docname)
ll_len_named = len(named)
ls_path = left(docname, ll_len_docname - ll_len_named)

ls_pathname= docname
ll_length=filelength(ls_pathname) //检查图片是否大于32765,因为fileread一次只能读32765
if ll_length>0 then //文件存在
if ll_length<32765 then //如果小于32765,就可以马上读出来
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 and not isnull(li_fh) then
FileRead(li_fh, blob_reader_pic)
FileClose(li_fh)
end if
else //当文件大于32765时
ll_size=ll_length/32765+1 //计算出fileread要花几次读出
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 then
for ll_i=1 to ll_size
FileRead(li_fh, blob_temp) //每次读出32765字节
blob_reader_pic=blob_reader_pic+blob_temp //将读出的内容累加到另一个二进制文件中
next
FileClose(li_fh)
else
messagebox('提示','错误')
return
end if
end if

ls_iccard_id=dw_2.object.vc_iccard_id[ll_row]

Updateblob readers
Set blob_pic =:blob_reader_pic
Where vc_iccard_id =:ls_iccard_id;

if sqlca.sqlcode = 0 then
commit;
else
MessageBox("提示","更新文件出错")
Rollback;
END IF
blob_reader_pic = blob("")
else
MessageBox("提示","文件<"+ls_pathname+">不存在!")
end if

1e21 2002-12-08
  • 打赏
  • 举报
回复
UP
flyhot 2002-12-08
  • 打赏
  • 举报
回复
gz
888888888888 2002-12-08
  • 打赏
  • 举报
回复
同意楼上的方法
andyzq 2002-12-08
  • 打赏
  • 举报
回复
保存文章的字段使用image类型

在pb中用filewrite()函数把一篇文章读到一个blob型变量中,然后使用
updateblob语句把保存文章的blob型变量存到数据库中
保存image类型的变量要注意两点
1.autocommit属性要设者为true (sqlca.autocommit=true )
2.保存image型数据的表中一定要有主键,即表中要现有记录存在,而且该条记录
是唯一的,别且拥有主键。

一个保存图片的例子:

integer li_fh, li_ret, li_value
blob blob_reader_pic,blob_temp
string ls_pathname,ls_iccard_id, ls_no
string docname, named, ls_path
long ll_length,ll_size, ll_i, ll_rowcount,ll_row
long ll_len_docname, ll_len_named

sqlca.autocommit = true

li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
if li_value <> 1 then return
ll_len_docname = len(docname)
ll_len_named = len(named)
ls_path = left(docname, ll_len_docname - ll_len_named)


ll_rowcount = dw_2.rowcount()
for ll_row=1 to ll_rowcount
sle_1.text=string(ll_row)+"/"+string(ll_rowcount)
ls_no=trim(dw_2.object.vc_reader_no[ll_row])
ls_pathname= ls_path +ls_no+ ".jpg"
ll_length=filelength(ls_pathname) //检查图片是否大于32765,因为fileread一次只能读32765

if ll_length>0 then //文件存在
if ll_length<32765 then //如果小于32765,就可以马上读出来
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 and not isnull(li_fh) then
FileRead(li_fh, blob_reader_pic)
FileClose(li_fh)
end if
else //当文件大于32765时
ll_size=ll_length/32765+1 //计算出fileread要花几次读出
li_fh = FileOpen(ls_pathname, StreamMode!, read!, Shared!, Replace!)
if li_fh <> -1 then
for ll_i=1 to ll_size
FileRead(li_fh, blob_temp) //每次读出32765字节
blob_reader_pic=blob_reader_pic+blob_temp //将读出的内容累加到另一个二进制文件中
next
FileClose(li_fh)
else
messagebox('提示','错误')
return
end if
end if

ls_iccard_id=dw_2.object.vc_iccard_id[ll_row]

Updateblob readers
Set blb_photo=:blob_reader_pic
Where vc_iccard_id =:ls_iccard_id;

if sqlca.sqlcode = 0 then
commit;
else
MessageBox("提示","更新照片出错")
Rollback;
END IF
blob_reader_pic = blob("")
else
MessageBox("提示","文件<"+ls_pathname+">不存在!")
end if
next

你使用的时候只需把
li_value = GetFileOpenName("读取照片",docname, named, "jpg","*.jpg,*.jpg,")
中'jpg'改为你要保存的文章的扩展名即可,
文本文件改为:
li_value = GetFileOpenName("读取文本",docname, named, "txt","*.txt,*.txt,") 等等

把sql语句中的表明和字段名改为你的就行了



humb 2002-12-08
  • 打赏
  • 举报
回复
多大的文章啊?什么都不说明怎么解答啊

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧