I'm new to JOOQ and using the latest version of JOOQ (3.10.5).
I am using it just as a SQL builder and not executing it against any DB.
I created the DSLContext using
Connection creatorConn = null;
creator = DSL.using(creatorConn, SQLDialect.MYSQL_8_0);
When i tried to concat an arbitrary String 'CC_' with a qualified field name field("TBL.[COLUMN NAME]") then resulting field is like
'CC'_ || "TBL.[COLUMN NAME]"
Then, when i use getSQL(), i got something like
select concat(?, TBL.[COLUMN NAME])
Can someone please tell me what went wrong and why is it the string concatenated has been replaced with a ?.
As per the solution posted here by Lukas Eder
I just added the
ParamType.INLINED to the Query.getSQL()
method which resolved this issue. Thanks
Related
I have created a new index that is populated using an indexer. The indexer's datasource is a SQL view that has a Timestamp column of type datetime. Since we don't want a full reindexing each time the indexer runs, this column should be used to determine which data have changed since the last indexer run.
According to the documentation we need to create or update the datasource by setting the HighWatermarkColumnName and ODataType to the DataChangeDetectionPolicy object. The example in the documentation uses the REST API and there is also way to do it using the azure search portal directly.
However I want to do it using .netsdk and so far I haven't been able to do so. I am using Azure.Search.Documents(11.2.0 - beta.2). Here is the part of the code I use to create the datasource:
SearchIndexerDataSourceConnection CreateIndexerDataSource()
{
var ds = new SearchIndexerDataSourceConnection(DATASOURCE,
SearchIndexerDataSourceType.AzureSql,
this._datasourceConStringMaxEvents,
new SearchIndexerDataContainer(SQLVIEW));
//ds.DataChangeDetectionPolicy = new DataChangeDetectionPolicy();
return ds;
}
The commented code is what I tried to do to initialize the DataChangeDetectionPolicy but there is no ctor exposed. Am I missing something?
Thanks in advance.
Instead of using DataChangeDetectionPolicy, you will need to use HighWaterMarkChangeDetectionPolicy which is derived from DataChangeDetectionPolicy.
So your code would be something like:
ds.DataChangeDetectionPolicy = new HighWaterMarkChangeDetectionPolicy("Timestamp");
When I follow this documentation:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalqueryableextensions.fromsqlraw?view=efcore-5.0 I get an error message:
FormatException: Input string was not in a correct format.
Example:
Context.Entity.FromSqlRaw("SELECT * FROM dbo.SomeFunction({#MyParameter})", new SqlParameter("#MyParameter", "some value"))
However, when I follow this documentation:
https://learn.microsoft.com/en-us/ef/core/querying/raw-sql
, the SQL created is sound and the query is executed correctly:
Example:
Context.Entity.FromSqlRaw("SELECT * FROM dbo.SomeFunction(#MyParameter)", new SqlParameter("#MyParameter", "some value"))
Here the parameters are specified without curly braces - which I think is logical, since there is no string interpolation going on here.
It seems to me that parts of the documentation are wrong. Or am I missing something?
As shown in my previous post QODBC/QODBC3 is not that good to work with databases. I have found a year old suggestion here to use ADODB for SQL Server. Can anyone give an example showing or suggest a link explaining How to connect, query and get result using ADODB.Connection in Qt?
You need to use QAxObject.
First you should take a look at:
QAxObject documentation: doc.qt.io/qt-5/qaxobject.html
Active X data object documentation: msdn.microsoft.com/en-us/library/windows/desktop/ms676795(v=vs.85).aspx
Here is a sample code to get you started:
// Create connection
QAxObject *connection = new QAxObject("ADODB.Connection");
connection->dynamicCall("Open(\"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Inaz;Data Source=SERVER02\")");
// Execute query and get recordset
QAxObject *recordSet = connection->querySubObject("Execute(\"select column01 from table01\")");
// Get fields
// or check https://msdn.microsoft.com/en-us/library/ms681510(v=vs.85).aspx to see what you can do with and how to use a recordset
QAxObject *fields = recordSet->querySubObject("Fields");
Note: You will need to call CoInitialize to use ADODB. However QGuiApplication and QApplication call it internally so you might not always need to make the call yourself.
I am just getting started on Apache Flink (Scala API), my issue is following:
I am trying to stream data from Kafka into Apache Flink based on one example from the Flink site:
val stream =
env.addSource(new FlinkKafkaConsumer09("testing", new SimpleStringSchema() , properties))
Everything works correctly, the stream.print() statement displays the following on the screen:
2018-05-16 10:22:44 AM|1|11|-71.16|40.27
I would like to use a case class in order to load the data, I've tried using
flatMap(p=>p.split("|"))
but it's only splitting the data one character at a time.
Basically the expected results is to be able to populate 5 fields of the case class as follows
field(0)=2018-05-16 10:22:44 AM
field(1)=1
field(2)=11
field(3)=-71.16
field(4)=40.27
but it's now doing:
field(0) = 2
field(1) = 0
field(3) = 1
field(4) = 8
etc...
Any advice would be greatly appreciated.
Thank you in advance
Frank
The problem is the usage of String.split. If you call it with a String, then the method expects it to be a regular expression. Thus, p.split("\\|") would be the correct regular expression for your input data. Alternatively, you can also call the split variant where you specify the separating character p.split('|'). Both solutions should give you the desired result.
On this question I solved the problem of querying Google Datastore to retrieve stuff by user (com.google.appengine.api.users.User) like this:
User user = userService.getCurrentUser();
String select_query = "select from " + Greeting.class.getName();
Query query = pm.newQuery(select_query);
query.setFilter("author == paramAuthor");
query.declareParameters("java.lang.String paramAuthor");
greetings = (List<Greeting>) query.execute(user);
The above works fine - but after a bit of messing around I realized this syntax in not very practical as the need to build more complicated queries arises - so I decided to manually build my filters and now I got for example something like the following (where the filter is usually passed in as a string variable but now is built inline for simplicity):
User user = userService.getCurrentUser();
String select_query = "select from " + Greeting.class.getName();
Query query = pm.newQuery(select_query);
query.setFilter("author == '"+ user.getEmail() +"'");
greetings = (List<Greeting>) query.execute();
Obviously this won't work even if this syntax with field = 'value' is supported by JDOQL and it works fine on other fields (String types and Enums). The other strange thing is that looking at the Data viewer in the app-engine dashboard the 'author' field is stored as type User but the value is 'user#gmail.com', and then again when I set it up as parameter (the case above that works fine) I am declaring the parameter as a String then passing down an instance of User (user) which gets serialized with a simple toString() (I guess).
Anyone any idea?
Using string substitution in query languages is always a bad idea. It's far too easy for a user to break out and mess with your environment, and it introduces a whole collection of encoding issues, etc.
What was wrong with your earlier parameter substitution approach? As far as I'm aware, it supports everything, and it sidesteps any parsing issues. As far as the problem with knowing how many arguments to pass goes, you can use Query.executeWithMap or Query.executeWithArray to execute a query with an unknown number of arguments.