DataTable output in AEP - advantage-database-server

When using a DataTable for output in a .Net AEP, how do I set the Output Parameter? What data type is used?
Thanks,
Howard

Are you wanting to just pass back the datatable as is to use in your application or are you wanting to pass back the equivalent of the datatable to the __output table the AEP uses to return the resultset?
If the datatable directly you could setup an output parameter of type memo and then insert into __output the XML of the datatable (you will probably need to use a stringwriter so you don't have to save it to a file)
Otherwise, the AEP will need to have one output parameter per column of your datatable. The types should be the same (in other words, if your datatable has int, char, int then your output parameters should be int, char, int).
In the AEP insert the values from your datatable into the __OUTPUT table. (i.e. add the datatable to a dataset, create a dataadapter and create the insert command using the commandbuilder then use dataadapter.update(dataset))

Related

deleting columns from influx DN using flux command line

Is there any way to delete columns of an influx timeseries as we have accidentally injected data using the wrong data type (int instead of float).
Or to change the type of data instead.
Unfortunately, there is no way to delete a "column" (i.e. a tag or a field) from an Influx measurement so far. Here's the feature request for that but there is no ETA yet.
Three workarounds:
use SELECT INTO to copy the desirable data into a different measurement, excluding the undesirable "columns". e.g.:
SELECT desirableTag1, desirableTag2, desirableField1, desirableField2 INTO new_measurement FROM measurement
use CAST operations to "change the data type" from float to int. e.g.:
SELECT desirableTag1, desirableTag2, desirableField1, desirableField2, undesiredableTag3::integer, undesiredableField3::integer INTO new_measurement FROM measurement
"Update" the data with insert statement, which will overwrite the data with the same timestamp, same tags, same field keys. Keep all other things equal, except that the "columns" that you would like to update. To make the data in integer data type, remember to put a trailing i on the number. Example: 42i. e.g.:
insert measurement,desirableTag1=v1 desirableField1=fv1,desirableField2=fv2,undesirableField1=someValueA-i 1505799797664800000
insert measurement,desirableTag1=v21 desirableField1=fv21,desirableField2=fv22,undesirableField1=someValueB-i 1505799797664800000

KSQL create table from stream for latest data

I have a topic called customers and I have created a stream for it
CREATE STREAM customers_stream (customerId INT, isActive BOOLEAN)
WITH (KAFKA_TOPIC='customers', VALUE_FORMAT='json');
My producer for customers topic is generating a Integer key and a json value. But when I see the row key is being set to a some binary value
ksql> print 'customers';
Format:JSON
{"ROWTIME":1570305904984,"ROWKEY":"\u0000\u0000\u0003�","customerId":1001,"isActive":true}
{"ROWTIME":1570307584257,"ROWKEY":"\u0000\u0000\u0003�","customerId":1002,"isActive":true}
Now if i create a table it results in a single row (maybe because row key is the same??)
CREATE TABLE customers (customerId INT, isActive BOOLEAN)
WITH (KAFKA_TOPIC='customers', KEY='customerId',VALUE_FORMAT='json');
After searching the web I bumped into this article https://www.confluent.io/stream-processing-cookbook/ksql-recipes/setting-kafka-message-key and created a new stream by repartitioning on the key
CREATE STREAM customers_stream2 AS \
SELECT * FROM customers_stream \
PARTITION BY customerId;
So how do I create a table which has the latest values of customers data?
creating a table from stream is resulting in a error
CREATE TABLE customers_2_table_active AS
SELECT CUSTOMERID,ISACTIVE
FROM customers_stream2;
Invalid result type. Your SELECT query produces a STREAM. Please use CREATE STREAM AS SELECT statement instead.
I need the latest value of the various rows so that another microservice can query the new table.
Thank you in advance
Rekeying seems to be the right approach, however, you cannot convert a STREAM into a TABLE directly.
Note, that your rekeyed stream customers_stream2 is written into a corresponding topic. Hence, you should be able to crate a new TABLE from the stream's topic to get the latest value per key.

In MVC, how can I retrieve records from database matching a range of string serial numbers that include numbers?

I have an MVC application that uses Code First Entity Framework.
I have records in my database for serial numbers that are strings, and a combination of letters and numbers. The last 4 are always the number part.
I am trying to retrieve all records in between range A and B, so for example from SERIAL-NO-0020 to SERIAL-NO-0050
I cannot convert the string number part to an integer because Linq To Entities doesn't support it. So as an example to get all records with a serial number higher than 20, this doesn't work:
var records = context.SerialNumbers.Where(m => Convert.ToDecimal(m.SerialNo.Substring(10, 4)) > 20).ToList();
Is there a way to do this without first pulling all the records from the database and filtering further?
Convert.ToDecimal can't be translated to SQL when using it with Linq to Entities.
You can create a stored procedure that query the data so you can do anyahting that can't be done by EF.
Another solution is to create a computed column.
First, add a new property. Let name it SerialId in your SerialNumber entity.
Second, Decorate that property with a data annotation:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
or use fluent configuration if you want:
modelBuilder.Entity<SerialNumber>().Property(t => t.SerialId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
Third, Add new EF migration and in the generated migration file, just update it by passing a new value to defaultValueSql parameter liek below:
public override void Up()
{
AddColumn(
"dbo.SerialNumber",
"SerialId",
c => c.Int(nullable: false, defaultValueSql: "CAST(SUBSTRING(SerialNo, 11, 4) AS INT)"));
}
The modification says that each line of SerialNumber table has a generated column and its value is calculated by using this SQL statement => CAST(SUBSTRING(SerialNo, 11, 4) AS INT)
You can update your database by running ef command => update-databse.
Finally, you can change your Linq to Entities like below and you don't need any conversion:
var records = context.SerialNumbers.Where(m => m.SerialId > 20).ToList();
Instead of Writing Queries you can write SP and access this SP (Stored Proceure) with the help of Linq.
In SP you can split the record first and then compare. It will also take less time and increase the performance.

Recognize the type of the parameters of a user defined sql to be used in a Delphi TQuery at runtime

I'm writing a delphi(7 ver) application and in some place I want to execute parameterized queries (for BDE and Paradox) which will be loaded at runtime into a TQuery by the user. These queries will be stored in text files (one text file for one query). The application then, will construct for any parameter of the query, one input control (Tedit) in order to be able to accept values by the user. Also there will be a button for the execution of query. My question is how can I recognize the datatype of the query's parameter? Is there a way to get this type without of cause to be included in some way in the text file containing the query?
Create a second query from the first, but modify its where clause to ensure no rows.
SELECT * FROM MYTABLE WHERE PKFIELD IS NULL
Name your parameters so that you can establish their datatypes from the fieldtypes of this second query.
I realise this only works for relatively simple cases, but it should get you some of the way.
the advantage of using a parameter is that you don't need to know its data type.
Use the string value from the tedit
"select * from mytable where myfield = :param1"
"parambyname('param1').asstring := edit1.text"
I've made this with MySQL database. you must define some parameters, Exemple:
SELECT * FROM MyTable WHERE MyField=[ANNEE];
in this case, i have an other table, called balise, that look like this
"ID" "BALISE" "CAPTION" "DEFAULT_VALUE" "CNDT" "COMPOSANT"
"1" "ANNEE" "Année" "2014" "Properties.MaxValue=2014||Properties.MinValue=2007" 1;
in runtime, this mean that:
Make in my Panel, a TLablel that have caption Année
Make in the same line an other component type 1 (That mean in my case TcxSpinEdit), this component have défault value 2014, have Two properties Max Value=2014 and Min Value=2007, (I use RTTI to modifie this value of parameters, in Delphi ver7, use TypeInfo).
An Other Button with function called Actualise, this function have Original query, must browse an array of TBalise that i have created, take the value (In my case, take TcxSpinEdit(MyObject).Value), and replace it in the copy of my query (AnsiReplaceStr(Requete, '[ANNEE]', MyValue)), so i have the final query to execute it.
I have module in complete projet, worked with this methode, and it workk fine.

Sorting Datatable with linq with correct datatype of a column

hello I have this code that use to sort a datatable.
Dim sortingIndex As Integer = orderby
Dim DataTableNew As DataTable = New DataTable
DataTableNew = dt.Clone
Dim query = (From c In dt.AsEnumerable Order By c.Field(Of String)(sortingIndex) Ascending)
query.CopyToDataTable(DataTableNew, LoadOption.OverwriteChanges)
My problem is that with this method I always need (Of String) for it to work, so the date columns are also managed as Strings witch is the problem. Is there a way to use the correct type so the sorting is based on the type of the column?
Linq rocks, but sometimes the good old methods are better. You can do
dt.Select(string.Empty,dt.Columns[sortingIndex].ColumnName)
It sorts the DataTable using the column's data type.

Resources