I am new to Ibatis. I have a query in Oracle which returns true or false using decode function:
SELECT decode(phone_number,null,null,'true') as GROUP_ASSIGNED ----- rest of the query
In this case how to map the resultset to the IBatis resultmap?
Thanks
Since the Oracle decode() function is just a if-then-else statement in disguise, you'd map the result (GROUP_ASSIGNED) column to an object property just like you would map any other returned column. Assuming you are mapping to an object with a property named GroupAssigned:
<resultMap ....
<result property="GroupAssigned" column="GROUP_ASSIGNED" />
Related
I want to query the url in a field value like this:
["{\"Success\":null,\"Fail\":null,\"Url\":\"http://www.baidu.com\",\"Method\":\"Post\",\"Data\":\"\",\"ContentType\":\"application/json\",\"Timeout\":120000,\"DelayFromMinutes\":15,\"Cron\":\"33 10 3/6 * * ?\",\"JobName\":\"Test#asyncOrder\",\"QueueName\":\"recurring\",\"AgentClass\":null,\"SendSuccess\":false,\"SendFail\":true,\"Mail\":\"xxxxxx#qq.com\",\"EnableRetry\":true,\"RetryDelaysInSeconds\":null,\"RetryTimes\":0,\"BasicUserName\":null,\"BasicPassword\":null,\"Headers\":{},\"CallbackEL\":null,\"TimeZone\":null,\"DingTalk\":null}","\"Test#asyncOrder\"","\"recurring\"","true",null]
What should I do?
I think I need some further clarification on this.
Are you trying to pass the entire json object into the query as an array of key-value pairs?
If so, do you want that pass to be all one string--commas, colons and everything?
OR are you passing the value for each key into its own parameter in the query?
In any event, I would likely want to utilize STRING_ESCAPE:
... WHERE Thing = STRING_ESCAPE(#Thing, 'json') ...
I need to project some fields from jsonb column where few of them are optional
I'm using EF Core 3.1 and npgsl and so far I got this
var shipments = _dbContext.Shipments.Select(x => new
{
ShipmentNo= x.ShipmentNumber,
ReportNum = x.ShipmentData.RootElement.GetProperty("reportNumber"),
ShipmentValue= x.ShipmentData.RootElement.GetProperty("shipmentMetadata").GetProperty("value").GetString(),
}
However value is optional and this is throwing exception. I see .TryGetProperty(...) method but it requires output variable and, I presume, its evaluation on server side. I wonder if there is way to handle this so query runs completely in Postgres.
You've forgotten to add GetInt32 (or whatever the type is) for reportNumber, just like you have a GetString after the shipmentMetadata. In order for this to be translatable to SQL, you need to tell the provider which type you expect to come out of the JSON element.
I created a database using MongoDB named mydb.
Then I created a collection called coll3
use mydb
db.coll3.insert({"1":"HI"})
When I do this
db.coll3.find()
I get this error
Couldn't retrieve documents
java.lang.IllegalStateException cannot be cast to t3.utils.document.g
You need to pass the query object (an empty object to return all documents) to the find function:
db.coll3.find({})
Refer to the MongoDB documentation.
Try:
db.getCollection('coll3').find({})
I am dealing with a stream of database mutations, i.e., a change log stream. I want to able to transform the values using a SQL query.
I am having difficulty putting together the following three concepts
RowTypeInfo, Row, and DataStream.
NOTE: I don't know the schema beforehand. I construct it on-fly using the data within the Mutation object (Mutation is a custom type)
More specifically I have code that looks like this.
val execEnv = StreamExecutionEnvironment.getExecutionEnvironment
val tableEnv: StreamTableEnvironment = TableEnvironment.getTableEnvironment(execEnv)
// Mutation is a custom type
val mutationStream: DataStream[Mutation] = ...
// toRows returns an object of type org.apache.flink.types.Row
val rowStream:DataStream[Row] = mutationStream.flatMap({mutation => toRows(mutation)})
tableEnv.registerDataStream("spinal_tap_table", rowStream)
tableEnv.sql("select col1 + 2")
NOTE: Row object is positional, and doesn't have a placeholder for column names.
I couldn't find a place to attach the schema to the DataStream object.
I want to pass some sort of a struct similar to Row that contains the complete information {columnName: String, columnValue: Object, columnType: TypeInformation[_]} for the query.
In Flink SQL a table schema is mandatory when the Table defined. It is not possible to run queries on dynamically typed records.
Regarding the concepts of RowTypeInfo, Row and DataStream:
Row is the actual record that holds the data
RowTypeInfo is a schema description for Rows. It contains names and TypeInformation for each field of a Row.
DataStream is a logical stream of records. A DataStream[Row] is a stream of rows. Note that this is not the actual stream but just an API concept to represent a stream in the API.
With doctrine and the query builder I write a SELECT MAX() query, and when this result is passed to another query builder, as a parameter, the query works just fine.
But for some reason, I use native SQL query elsewhere in another Repository, and when I use $repo->getMaxMyThing(), it return me an array of array like
array(array('1' => 42)).
Not that if I want the result, I need to type: $max[0]['1'] (The 0 is a simple array index, but the '1' is a string associated key).
Did any method exists in the Doctrine Bundle to 'convert' it to a simple integer automatically?
When you don't want Doctrine to return entities, you can use the get*ScalarResult() query methods.
Query#getScalarResult(): Retrieves a flat/rectangular result set of scalar values that can contain duplicate data. The pure/mixed distinction does not apply.
Query#getSingleScalarResult(): Retrieves a single scalar value from the result returned by the dbms. If the result contains more than a single scalar value, an exception is thrown. The pure/mixed distinction does not apply.
Here is an example from the documentation:
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
$count = $query->getSingleScalarResult();
$count will be a single value (not an array) as requested.