我们的oracle数据库无法更改,并且有很多cols表示为CHARS。目前,我在进行比较时手动将参数填充到字段的长度,例如给定foo是db'foo'
中的char(5)<?php
class MyStreamReader extends \OwlyCode\StreamingBird
{
protected $stream;
protected function connect($timeout = 5, $attempts = 10)
{
return $this->stream = parent::connect($timeout, $attempts);
}
protected function isConnected()
{
return $this->stream && stream_get_meta_data($this->stream)['eof'];
}
}
class MyStreamingBird extends \OwlyCode\StreamingBird
{
public function createStreamReader($method)
{
$oauth = new \OwlyCode\StreamingBird\Oauth($this->consumerKey,
$this->consumerSecret, $this->oauthToken, $this->oauthSecret);
return new MyStreamReader(new \OwlyCode\StreamingBird\Connection(), $oauth, $method);
}
}
$bird = new MyStreamingBird($consumerKey, $consumerSecret, $oauthToken, $oauthSecret);
$reader = $bird->createStreamReader(StreamReader::METHOD_FILTER); // ...
$reader->isConnected();
有什么方法我可以告诉jooq foo是一个char因此它执行填充比较,例如生锈的机器人回答here
答案 0 :(得分:1)
您可以为所有CHAR
列实现data type binding,并在生成的SQL字符串中强制转换绑定变量:
@Override
public final void sql(BindingSQLContext<String> ctx) throws SQLException {
ctx.render().sql("CAST(? AS CHAR(5))");
}
(我刚才注意到无法以这种方式访问CHAR
长度...,这应该是固定的:https://github.com/jOOQ/jOOQ/issues/5223)
或者在将绑定变量绑定到预准备语句之前缩短/填充绑定变量。或者您可以直接在数据类型绑定的变量绑定逻辑中use that logic you referenced to。
@Override
public final void set(BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement()
.unwrap(OraclePreparedStatement.class)
.setFixedChar(ctx.index(), ctx.value());
}
这些方法中的任何一种都只允许您实现此逻辑一次。