PB数据窗口不能返回Mysql自增列 identity 的问题

PB用ODBC连接Mysql,在数据窗口中插入一条记录,向数据库提交记录后不能自动返回自增列 id(identity value ),在SQL Server下是可以自动返回自增列 id。

测试表test定义如下:

CREATE TABLE test (
  id INT NOT NULL AUTO_INCREMENT,
  stuname VARCHAR(32) NOT NULL,
  PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8

根据网上一些资料在 pbodb125.ini 文件中增加如下配置,还是不能成功。希望有技术大拿一起交流解决方案。(修改C:\Users\Administrator\appdata\Local\Sybase\PowerBuilder 12.5下的pbodb125.ini成功解决问题)参见:

https://answers.sap.com/questions/10891078/powerbuilder-125-did-not-return-the-identity-value.html

[MySQL]
PBSyntax='MySQL_SYNTAX'
[MySQL_SYNTAX]
GetIdentity='Select @@identity'
;GetIdentity='SELECT LAST_INSERT_ID()'

最后在dw的 updateend 事件中加入代码手动取得 id 临时解决:

// updateend()
// 解决MySQL不能自动返回自增ID的问题
if Lower(describe("id.type")) = "column"  then
	long ll_id
	int  i,li_rows
	if uf_getsqlid(1,ref ll_id)="MYSQL" then //返回自增ID
		li_rows = this.RowCount()
		if ll_id>0 and li_rows>0 then
			for i=li_rows to 1 step -1
			if GetItemStatus(i,0,Primary!)=NewModified! then //update(false,false)
				this.object.id.Primary.Original[i] = ll_id	
				ll_id=ll_id -1
			end if
			next
		end if
	end if
end if

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值