This document explains how to implement the new feature of the DataWindow which uses stored procedures to insert, update, and delete data from a database
Overview
In previous versions of PowerBuilder, it was possible to use a stored procedure as a datasource
for a DataWindow, however to use a stored procedure for update, insert or delete, the SQLPreview
event had to be used to substitute the generated SQL statement for a stored procedure call.
PowerBuilder 7.0 adds direct support for stored procedures for update, insert and delete actions.
This makes it possible to design a DataWindow entirely on stored procedures within the painter.
Specifying Update Properties
When a DataWindow is based on a stored procedure, the DataWindow is by default not updateable. When stored procedures are used for all three updating actions, it is not necessary to change the properties the Specify Update Properties dialog, but the taborder of the columns to be updated must be set to a non-zero, positive, number.
In the following example a set of simple ASA stored procedures are given for updating the EAS Demo DB department table. The stored procedure sp_select_departments can be used as a datasource for the DataWindow as usual, however the other three procedures must be associated using the Stored Procedure Update menu item.
//Note : The tilde character "~" represents the terminator character.
drop procedure sp_select_departments ~
drop procedure sp_insert_department ~
drop procedure sp_update_department ~
drop procedure sp_delete_department ~
create procedure sp_select_departments()
result (dept_id int, dept_name char(40), dept_head_id int)
begin
select dept_id, dept_name , dept_head_id
from department
end~
create procedure sp_insert_department(in id int, in name char(40), in head_id int)
begin
insert into department
values (id, name, head_id)
end~
create procedure sp_update_department(in old_id int, in new_id int, in name char(40), in head_id int)
begin
update department
set dept_id = new_id,
dept_name = name ,
dept_head_id= head_id
where dept_id = old_id
end~
create procedure sp_delete_department(in id int)
begin
delete from department where dept_id = id
end~
The stored procedure arguments must match the columns of the DataWindow. For each argument, you can specify to use the original value or the current value. The original value is typically used in the where clause. For example in the procedure sp_update_department you would check Use Original for the old_id argument and uncheck it for the new_id, name and head_id arguments.

Working with different databases
The Stored Procedure Update functionality is not dependent on the particular database used, although the database itself can pose certain restrictions. Similar procedure sets can be defined for other databases like Sybase ASE or Oracle.
// ASE syntax
drop procedure sp_select_departments ~
drop procedure sp_insert_department ~
drop procedure sp_update_department ~
drop procedure sp_delete_department ~
create procedure sp_select_departments
as
begin
select dept_id, dept_name , dept_head_id
from department
end~
create procedure sp_insert_department(@dept_id int, @dept_name char(40), @dept_head_id int)
as
begin
insert into department
values (@dept_id, @dept_name, @dept_head_id)
end~
create procedure sp_update_department(@old_dept_id int, @new_dept_id int, @dept_name char(40), @dept_head_id int)
as
begin
update department
set dept_id = @new_dept_id,
dept_name = @dept_name ,
dept_head_id= @dept_head_id
where dept_id = @old_dept_id
end~
create procedure sp_delete_department(@dept_id int)
as
begin
delete from department where dept_id = @dept_id
end~
Either a stored procedure or a sql-statement can perform each of the separate SQL actions Update Insert or Delete. But if the DataWindow is not updateable, only those actions with type Stored Procedure will be carried out.
At run-time it can be verified by checking the value of the dw_control.Object.DataWindow.Table.SqlAction.Type
in which sqlaction can be either Update Insert or Delete. Also the Method (stored procedure) and the Arguments are available at run-time and can be modified after the Type has been set to SP.
The stored procedure will usually be prefixed by its owner. Most databases don't require an owner name before the stored procedure name, however you will have to verify this with your database vendor (ASE requires the owner name to prefix the stored procedure i.e. dbo.sp_update.)
The support for the stored procedure datasource hasn't been changed in PB7, so that the same script rules apply as in earlier versions.
In the following Oracle example the stored procedure for retrieval is rewritten using the PBDBMS package.
// Oracle syntax using PBDBMS
drop procedure sp_select_departments ~
drop procedure sp_insert_department ~
drop procedure sp_update_department ~
drop procedure sp_delete_department ~
create procedure sp_select_department
as
begin
PBDBMS.Put_Line('select dept_id, dept_name , dept_head_id ');
PBDBMS.Put_Line('from department');
end~
create procedure sp_insert_department(id in int, name in varchar2, head_id in int)
as
begin
insert into department
values (id, name, head_id);
end~
create procedure sp_update_department(old_id in int, new_id in int, name in varchar2, head_id in int)
as
begin
update department
set dept_id = new_id,
dept_name = name ,
dept_head_id= head_id
where dept_id = old_id;
end~
create procedure sp_delete_department(id in int)
as
begin
delete from department where dept_id = id;
end~
select * from all_errors~
A package with suitable stored procedures could also have been used, in which case the method must be prefixed by the package name (see also Tech Doc 44450 and 44553).
Note:
PowerBuilder does not retrieve a list of stored procedures that are contained within packages so that they cannot be selected in the painter. But the stored procedures can be executed at run-time.
An example script
Suppose similar sets of stored procedures exists within and ASA, ASE and Oracle Server; and the Oracle update procedures have been defined in the package SYSTEM.PKG_SPDWC. The following script fragment gives an example on how the DataWindow can call different stored procedures dependant on the database server the application is connected to. The script can be generalized in many ways, for example the names of the stored procedures don't have to be hard-coded but could also have been stored in an ini file or even in the database.
// current server
string gs_server
// list of servers
string gs_servers[] = {"my_ASA_server", "my_O84_server", "my_SYC_server")
// list of stored procedures for the different databasesdatabases.
string is_spupdates[] = {"sp_update_department", "SYSTEM.PKG_SPDWC.sp_update_department", "dbo.sp_update_department"}
string is_spinsertes[] = {"sp_insert_department", "SYSTEM.PKG_SPDWC.sp_insert_department", "dbo.sp_insert_department"}
string is_spdeletes[] = {"sp_delete_department", "SYSTEM.PKG_SPDWC.sp_delete_department", "dbo.sp_delete_department"}
string is_spselect[] = {"sp_select_department", "SYSTEM.sp_select_department", "dbo.sp_select_department"}
// list of stored procedures the DataWindow was created upon
string ls_default_update = "dbo.sp_update_department"
string ls_default_insert = "dbo.sp_insert_department"
string ls_default_delete = "dbo.sp_delete_department"
string ls_default_select = "dbo.sp_select_department"
// Replace example script :
string ls_update_method, ls_insert_method, ls_delete_method, ls_select_method
integer l_upper, li_i = 0
boolean b_found = false
//check which is the current server
li_upper = UpperBound(gs_servers)
for li_i = 1 to li_upper
if gs_servers[li_i] = gs_server then
b_found = true
exit
end if
next
//replace the names of the stored procedures
if b_found then
ls_update_method = dw_1.Object.DataWindow.Table.UPDATE.Method
ls_insert_method = dw_1.Object.DataWindow.Table.INSERT.Method
ls_delete_method = dw_1.Object.DataWindow.Table.DELETE.Method
ls_select_method = dw_1.object.DataWindow.Table.Procedure
dw_1.Object.DataWindow.Table.UPDATE.Method = gf_substitute(ls_update_method, ls_default_update, is_spupdates[li_i])
dw_1.Object.DataWindow.Table.INSERT.Method = gf_substitute(ls_insert_method, ls_default_insert, is_spinsertes[li_i])
dw_1.Object.DataWindow.Table.DELETE.Method = gf_substitute(ls_delete_method, ls_default_delete, is_spdeletes[li_i])
dw_1.object.DataWindow.Table.Procedure = gf_substitute(ls_select_method, ls_default_select, is_spselect[li_i])
else
MessageBox("Error Unknown Server", "No Match : " + gs_server)
end if
//global substitute string function
string function gf_substitute(as_1, as_2, as_3)
integer li_pos, li_1, li_2, li_3
string ls
li_pos = pos(as_1, as_2)
li_1 = len(as_1)
li_2 = len(as_2)
li_3 = len(as_3)
if li_pos > 0 and li_3 > 0 then
ls = left(as_1, li_pos - 1) + as_3 + right(as_1, li_1 - li_2 - li_pos + 1)
分享到:
相关推荐
PowerBuilder通过数据窗口(Datawindow)产生SQL语句,或者调用存储过程(Stored Procedure),并提交给SQL Server进行事务处理。同时,PowerBuilder也可以直接使用嵌入的(Embedded)SQL语句、调用存储过程或动态...
- **存储过程(Stored Procedure)**:预先编译并存储在数据库中的SQL代码块,可提高性能和复用性。 #### 数据类型 - **数值类型**(如 Integer、Float):用于存储整数和浮点数。 - **字符类型**(如 Char、Varchar...
- **存储过程(Stored Procedure):** 预编译的SQL代码集合,提高了执行效率。 - **触发器(Trigger):** 当特定事件发生时自动执行的SQL代码段。 - **索引(Index):** 用于加速数据检索的结构。 - **序列(Sequence):** ...
qt 一个基于Qt Creator(qt,C++)实现中国象棋人机对战.
热带雨林自驾游自然奇观探索
冰川湖自驾游冰雪交融景象
C51 单片机数码管使用 Keil项目C语言源码
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
前端分析-2023071100789s12
Laz_制作了一些窗体和对话框样式.7z
1、文件内容:ocaml-docs-4.05.0-6.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/ocaml-docs-4.05.0-6.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
学习笔记-沁恒第六讲-米醋
工业机器人技术讲解【36页】
内容概要:本文档详细介绍了在 CentOS 7 上利用 Docker 容器化环境来部署和配置 Elasticsearch 数据库的过程。首先概述了 Elasticsearch 的特点及其主要应用场景如全文检索、日志和数据分析等,并强调了其分布式架构带来的高性能与可扩展性。之后针对具体的安装流程进行了讲解,涉及创建所需的工作目录,准备docker-compose.yml文件以及通过docker-compose工具自动化完成镜像下载和服务启动的一系列命令;同时对可能出现的问题提供了应对策略并附带解决了分词功能出现的问题。 适合人群:从事IT运维工作的技术人员或对NoSQL数据库感兴趣的开发者。 使用场景及目标:该教程旨在帮助读者掌握如何在一个Linux系统中使用现代化的应用交付方式搭建企业级搜索引擎解决方案,特别适用于希望深入了解Elastic Stack生态体系的个人研究与团队项目实践中。 阅读建议:建议按照文中给出的具体步骤进行实验验证,尤其是要注意调整相关参数配置适配自身环境。对于初次接触此话题的朋友来说,应该提前熟悉一下Linux操作系统的基础命令行知识和Docker的相关基础知识
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
网络小说的类型创新、情节设计与角色塑造
毕业设计_基于springboot+vue开发的学生考勤管理系统【源码+sql+可运行】【50311】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - 业务管理:班级信息、学生信息、课程信息、考勤记录、假期信息、公告信息 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!
在智慧城市建设的大潮中,智慧园区作为其中的璀璨明珠,正以其独特的魅力引领着产业园区的新一轮变革。想象一下,一个集绿色、高端、智能、创新于一体的未来园区,它不仅融合了科技研发、商业居住、办公文创等多种功能,更通过深度应用信息技术,实现了从传统到智慧的华丽转身。 智慧园区通过“四化”建设——即园区运营精细化、园区体验智能化、园区服务专业化和园区设施信息化,彻底颠覆了传统园区的管理模式。在这里,基础设施的数据收集与分析让管理变得更加主动和高效,从温湿度监控到烟雾报警,从消防水箱液位监测到消防栓防盗水装置,每一处细节都彰显着智能的力量。而远程抄表、空调和变配电的智能化管控,更是在节能降耗的同时,极大地提升了园区的运维效率。更令人兴奋的是,通过智慧监控、人流统计和自动访客系统等高科技手段,园区的安全防范能力得到了质的飞跃,让每一位入驻企业和个人都能享受到“拎包入住”般的便捷与安心。 更令人瞩目的是,智慧园区还构建了集信息服务、企业服务、物业服务于一体的综合服务体系。无论是通过园区门户进行信息查询、投诉反馈,还是享受便捷的电商服务、法律咨询和融资支持,亦或是利用云ERP和云OA系统提升企业的管理水平和运营效率,智慧园区都以其全面、专业、高效的服务,为企业的发展插上了腾飞的翅膀。而这一切的背后,是大数据、云计算、人工智能等前沿技术的深度融合与应用,它们如同智慧的大脑,让园区的管理和服务变得更加聪明、更加贴心。走进智慧园区,就像踏入了一个充满无限可能的未来世界,这里不仅有科技的魅力,更有生活的温度,让人不禁对未来充满了无限的憧憬与期待。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
内容概要:本文介绍了使用 Matlab 实现基于 BO(贝叶斯优化)的 Transformer 结合 GRU 门控循环单元时间序列预测的具体项目案例。文章首先介绍了时间序列预测的重要性及其现有方法存在的限制,随后深入阐述了该项目的目标、挑战与特色。重点描述了项目中采用的技术手段——结合 Transformer 和 GRU 模型的优点,通过贝叶斯优化进行超参数调整。文中给出了模型的具体实现步骤、代码示例以及完整的项目流程。同时强调了数据预处理、特征提取、窗口化分割、超参数搜索等关键技术点,并讨论了系统的设计部署细节、可视化界面制作等内容。 适合人群:具有一定机器学习基础,尤其是熟悉时间序列预测与深度学习的科研工作者或从业者。 使用场景及目标:适用于金融、医疗、能源等多个行业的高精度时间序列预测。该模型可通过捕捉长时间跨度下的复杂模式,提供更为精准的趋势预判,辅助相关机构作出合理的前瞻规划。 其他说明:此项目还涵盖了从数据采集到模型发布的全流程讲解,以及GUI图形用户界面的设计实现,有助于用户友好性提升和技术应用落地。此外,文档包含了详尽的操作指南和丰富的附录资料,包括完整的程序清单、性能评价指标等,便于读者动手实践。