怎样通过pb源码和旧的数据库找出缺少的字段?

wlings 2008-04-18 11:43:05
最新的数据库坏了,只有一个旧的数据库和最新的pb源码,因为后面加了些字段,用旧的数据库运行时会有些地方出错,又没有做好数据库修改记录,程序编译的时候是不会查出数据窗口或按扭、函数等的sql语句有没有缺字段的,只能是打开这些函数或窗口保存一下才能发现问题,但有很多个窗口和函数呀,要一个个打开太麻烦了,有什么好的办法可以快速找出我的程序在旧的数据库中缺哪些表或字段呀?
...全文
77 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jdsnhan 2008-04-21
  • 打赏
  • 举报
回复
没啥好法,恢复数据库吧,呵呵。
编程夜猫 2008-04-21
  • 打赏
  • 举报
回复
似乎这类需求,都没有简便的方法,呵呵。无论你是否导出源文件,还是得一个对象一个对象去找。呵呵。省不了的
orcd 2008-04-21
  • 打赏
  • 举报
回复



end subroutine

on w_main.create
this.dw_2=create dw_2
this.mle_status=create mle_status
this.cb_1=create cb_1
this.dw_6=create dw_6
this.Control[]={this.dw_2,&
this.mle_status,&
this.cb_1,&
this.dw_6}
end on

on w_main.destroy
destroy(this.dw_2)
destroy(this.mle_status)
destroy(this.cb_1)
destroy(this.dw_6)
end on

type dw_2 from datawindow within w_main
integer x = 105
integer y = 216
integer width = 2327
integer height = 724
integer taborder = 20
string title = "none"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type mle_status from multilineedit within w_main
integer x = 128
integer y = 1112
integer width = 2277
integer height = 248
integer taborder = 30
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
end type

type cb_1 from commandbutton within w_main
integer x = 1120
integer y = 88
integer width = 457
integer height = 128
integer taborder = 20
integer textsize = -12
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "执行"
end type

event clicked;//====================================================================
// 事件: cb_30::clicked
//--------------------------------------------------------------------
// 描述: 找到所有的数据对象
//--------------------------------------------------------------------
// 参数:
// (无)
//--------------------------------------------------------------------
// 返回值: long
//--------------------------------------------------------------------
// 作者: friendwaters 日期: 2006-01-06
//--------------------------------------------------------------------
// 修改历史: hahahahahah
// 1221212121aaaaaaaaa
//====================================================================
dw_6.SetTransObject(sqlca)

String ls_tabname,ls_tablename
String ls_sql,ls_syntax
String ls_a
String ls_name
Int li_j,li_i
ls_a = "BBGL.PBL;CKGL.PBL;CKGLBB.PBL;CXGL.PBL;CXGLBB.PBL;DJCD.PBL;DJFC.PBL;ERP.PBL;error.pbl;exfuns.pbl;GSGGL.PBL;GSPGLBB.PBL;jbxxbb.pbl;JCGLBB.PBL;JXGL.PBL;jyfx.pbl;LSGL.PBL;LSGLBB.PBL;msgbox_help.pbl;PRINT.PBL;pzti.pbl;rsgzgl.pbl;SUN_ADD.PBL;SUNCALN.PBL;SUNDLG.PBL;SUNFUN1.PBL;SUNTOOLS.PBL;SUNYYGL.PBL;THGL.PBL;YYGL_JBXX1.PBL;yygl_jbxx2.pbl;YYGL_RYYW1.PBL;ZHGLBB.PBL;print_jx_ck.pbl";

li_j = 0
For li_i = 1 To Len(ls_a)
If Mid(ls_a,li_i,1) = ';' Then
ls_name = Mid(ls_a,li_j+1,li_i - (li_j+1))

String ls_title, ls_pathfile, ls_file, ls_ext, ls_filter, ls_path
String ls_objname
Int li_return, li_readlen, li_namelen, li_pos
Blob lb_buf

// ls_title = '选择文件'
// ls_filter = 'PowerBuider动态库文件(*.pbl), *.pbl'
//
// li_return = GetFileOpenName(ls_title, ls_pathfile, ls_file, ls_ext, ls_filter)
// if li_return <> 1 then return
//
ls_pathfile = "M:\pb资料\PB连锁药店GSP-做的很复杂060713\PB连锁药店GSP\"+ls_name

li_return = FileOpen(ls_pathfile, streammode!, Read!, Shared!)
If li_return <= 0 Then
MessageBox('', '不能打开文件: ' + ls_pathfile)
Return
End If

// lv_dwlist.DeleteItems()



//============================================================
// string变量将null(ASCII值=0)当作结束符,而pbd文件中null泛滥,
// 只能使用blob变量做中转,而且要准确定位,不能搜索
//============================================================

li_readlen = FileRead(li_return, lb_buf)
li_pos = 1057 //第一个对象的入口
Do While String(BlobMid(lb_buf, li_pos, 4)) = 'ENT*' //对象起始标志
li_pos += 22 //存放名称的长度
li_namelen = Asc(String(BlobMid(lb_buf, li_pos, 1)))
li_pos += 2 //名称起始位置
ls_objname = String(BlobMid(lb_buf, li_pos, li_namelen))
If Right(ls_objname, 4) = '.dwo' Then

ls_objname = Left(ls_objname, li_namelen - 5)
Integer li_filenum


//====================================================================
// 用游标取表的名字,用来判断,数据对象中调用了哪些表
// 取到一个数据对象,然后取表的名字
//====================================================================

dw_6.DataObject = ls_objname
ls_syntax = dw_6.Describe('datawindow.syntax')
//messagebox('',ls_syntax)
wf_updatealldw( ls_objname,ls_name,ls_syntax)


li_filenum = FileOpen("E:\所有的dw.txt", streammode!, Write!, lockreadwrite!, append!)

If FileWrite(li_filenum, ls_objname+"~r~n") = -1 Then
mle_status.Text = mle_status.Text +"~r~n"+"写入了文件+所有的dw中"+ls_objname
MessageBox('','写文件出错')
End If
FileClose(li_filenum)

End If
li_pos += li_namelen
Loop

FileClose(li_return)
li_j = li_i
End If


Next
MessageBox('提示','写文件完成')









end event

type dw_6 from datawindow within w_main
integer x = 96
integer y = 36
integer width = 686
integer height = 400
integer taborder = 10
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

orcd 2008-04-21
  • 打赏
  • 举报
回复
上面的方法只能一个一个窗口的做.感觉很麻烦.
其实是可以找到每个数据窗口中使用了哪些表,然后再根据数据库中系统表的记录来得到一个结果.
下面这个你保存成srw文件导入到你的程序中看看,这个只完成了第一步得到数据窗口和表的对应关系
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type dw_2 from datawindow within w_main
end type
type mle_status from multilineedit within w_main
end type
type cb_1 from commandbutton within w_main
end type
type dw_6 from datawindow within w_main
end type
end forward

global type w_main from window
integer width = 2606
integer height = 1616
boolean titlebar = true
string title = "得到数据窗口和表的对应关系"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
dw_2 dw_2
mle_status mle_status
cb_1 cb_1
dw_6 dw_6
end type
global w_main w_main

type variables
long ll_start, ll_used
end variables

forward prototypes
public subroutine wf_updatealldw (string as_dw, string as_pbl, string as_syntax)
end prototypes

public subroutine wf_updatealldw (string as_dw, string as_pbl, string as_syntax);//====================================================================
// 函数: w_popuppaint::wf_updatealldw
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
// value string as_dw
// value string as_pbl
// value string as_syntax
//--------------------------------------------------------------------
// 返回值: (none)
//--------------------------------------------------------------------
// 作者: friendwaters 日期: 2006-01-07
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================

String ls_tabname,ls_sql
String ls_a
Int li_cnt
SELECT count(*)
INTO :li_cnt
FROM sysobjects
where Name = 't_tablebydw';
If li_cnt < 1 Then
ls_sql = "CREATE TABLE [dbo].[t_tablebydw] ("&
+"[fdw] [varchar] (50) NULL ,"&
+"[fpbl] [varchar] (50) NULL ,"&
+"[ftable] [varchar] (100) NULL"&
+") ON [PRIMARY]"
EXECUTE Immediate :ls_sql;
If sqlca.SQLCode <> 0 Then
MessageBox('提示','创建表出现错误,~r~n错误信息为:'+sqlca.SQLErrText)
Else
End If
Else
// SELECT count(*)
// INTO :li_cnt
// From t_tablebydw;
// If li_cnt > 0 Then
// ls_sql = 'truncate table t_tablebydw'
// EXECUTE Immediate :ls_sql;
// If sqlca.SQLCode <> 0 Then
// MessageBox('提示','清空表出现错误,~r~n错误信息为:'+sqlca.SQLErrText)
// Else
// End If
// Else
// End If
End If
//select
DECLARE cur_tab CURSOR FOR
SELECT name
FROM sysobjects
WHERE ( sysobjects.xtype = 'u' ) OR
( sysobjects.xtype = 'v' )
order by sysobjects.Name;
OPEN cur_tab;
FETCH cur_tab Into :ls_tabname;

Do While sqlca.SQLCode = 0

If Pos(as_syntax,ls_tabname,1) > 0 Then //假如这个数据窗口调用了这个表
If IsNull(ls_a) Or ls_a = "" Then
ls_a = ls_tabname
Else
ls_a += "++"+ls_tabname
End If

Else

End If

FETCH cur_tab Into :ls_tabname;
Loop
//messagebox('',as_syntax)
INSERT INTO t_tablebydw
VALUES(:as_dw,:as_pbl,:ls_a)
COMMIT;
mle_status.Text = "在数据库中插入了值"+as_dw+"~r~n"+as_pbl+"~r~n"+ls_a

CLOSE cur_tab;

lllyyymmm 2008-04-21
  • 打赏
  • 举报
回复
只能一个一个的试了,发现少什么及时加上去,没什么好的方法
csdn00 2008-04-21
  • 打赏
  • 举报
回复
经常备份数据库不错奥。

目前只能一个一个凭借记忆去找了
myvicy 2008-04-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 SummerHeart 的回复:]
似乎这类需求,都没有简便的方法,呵呵。无论你是否导出源文件,还是得一个对象一个对象去找。呵呵。省不了的
[/Quote]
青锋-SS 2008-04-18
  • 打赏
  • 举报
回复
1.dw_1.getsqlselect()获取这个数据窗口的select语句,然后就可以分离出所有的字段
2.从数据库的syscolumns表中获取该表所有的字段
3.进行比较

754

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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