How to fetch DeviceScope using iot-service-client java - azure

I am trying to fetch the deviceScope of the deviceTwin. However, the deviceScope is not returned in the DeviceTwinDevice.
String iotHubConnectionString = "xxx";
DeviceTwin twinClient = DeviceTwin.createFromConnectionString(iotHubConnectionString);
SqlQuery sqlQuery = SqlQuery.createSqlQuery("*",SqlQuery.FromType.DEVICES,"capabilities.iotEdge=false",null);
Query twinQuery = twinClient.queryTwin(sqlQuery.getQuery());
DeviceTwinDevice d = twinClient.getNextDeviceTwin(twinQuery);

Thanks to https://github.com/Azure/azure-iot-sdk-java/issues/1157. Have to use registerManager

Related

Is this type of query safe from sql injection?

let tableName = req.body.tableName
let colName = req.body.col1+","+req.body.col2
sqlString = INSERT INTO ${tableName}(${colName}) VALUES ($1,$2) RETURNING *
No, you are using user's input as is inside a SQL query.
Use some kind of query builder like knex, which has a built in way of escaping user's input properly.

How to insert data in mysql database using C#

string query2 = "INSERT INTO library_database.status_of_issue VALUES('";
query2 = query2 +textBox2.Text + "','";
query2 = query2 + textBox1.Text + "', CURDATE(),ADDDATE(CURDATE(), INTERVAL 14 DAY)";
cmd = new MySqlCommand(query2, con);
MySqlDataReader d1 = cmd.ExecuteReader();
MessageBox.Show("Issed...");
d1.Close();
Missing the closing parenthesys for the VALUES clause, but your query should be rewritten to avoid Sql Injection and an INSERT query is executed with ExecuteNonQuery
string query2 = #"INSERT INTO library_database.status_of_issue VALUES(#p1, #p2,
CURDATE(),ADDDATE(CURDATE(), INTERVAL 14 DAY))";
cmd = new MySqlCommand(query2, con);
cmd.Parameters.AddWithValue("#p1", textBox2.Text);
cmd.Parameters.AddWithValue("#p2", textBox1.Text);
int rows = cmd.ExecuteNonQuery();
if(rows > 0)
MessageBox.Show("insert OK...");
So very obvious. You're missing the ending paranthesis of VALUES. This should work:
string query2 = string.Format("INSERT INTO library_database.status_of_issue VALUES('{0}', '{1}', CURDATE(), ADDDATE(CURDATE(), INTERVAL 14 DAY))", textBox2.Text, textBox1.Text);
using(var cmd = new MySqlCommand(query2, con))
{
if(cmd.ExecuteNonQuery() > 0)
MessageBox.Show("Issed...");
}
Also note that INSERT, UPDATE and DELETE commands should be executed using ExecuteNonQuery().

Mapping to Dictionary collection in PetaPoco?

way to map the following to a Dictionary??
Sql sql = new Sql()
.Append("SELECT Count(*) ")
.Append("FROM Custumers")
.Append("WHERE CustomerId = #0", Id)
var result = database.Fetch<Dictionary<int,DateTime>>(sql);
I cannot use List as DateTime is also thr.
Petapoco always return a List<T>, but you can convert the List to a Dictionary afterwards:
var result = database
.Fetch<Pair<int,DateTime>>(sql)
.ToDictionary(i => i.ID, i => i.Date);
With NPoco you can write this: it will use the first 2 columns
var result = database.Dictionary<int, DateTime>(sql);
or use what #Eduardo said.

Big query Query Statistics

How to get query Statistics such as Time Taken to execute and other parameters in Bigquery using C#.
QueryRequest _r = new QueryRequest();
_r.Query = "SELECT Id, Name FROM [Sample.Test] LIMIT 1000";
QueryResponse _qr = _service.Jobs.Query(_r, "samplequery").Fetch();
List<string> _fieldNames = _qr.Schema.Fields.ToList().Select(x => x.Name).ToList() ;
List<Google.Apis.Bigquery.v2.Data.TableRow> _rows = _qr.Rows.ToList();
There is JobStatistics Class, but i am not getting job statistics from above query execution. Else If there is any other way to get statistics pls suggest.
Thanks
I got it.
Job _j = _service.Jobs.Get(_qr.JobReference.ProjectId, _qr.JobReference.JobId).Fetch();
JobStatistics _js = _j.Statistics;
this.StartTime = _js.StartTime;
this.EndTime = _js.EndTime;
this.BytesProcessed = _js.TotalBytesProcessed;

SubSonic "Or" and "AND"

How to make this select in SubSonic using SqlQuery ?
SELECT * FROM [dbo].[Tablexxx]
Join Tableyyy on Tablexxx.fieldZZZ = Tableyyy.fieldZZZ
WHERE Tablexxx.fieldxxx = 1 AND
(Tablexxx.fieldyyy = 'S' or Tablexxx.fieldyyy = 'T')
Thanks any help.
Valmir
var query = DB.Select().From<Table1>()
.InnerJoin<Table2>()
// Where() takes a ColumnSchema type
.Where(Table1.FieldXColumn).IsEqualTo(1)
// AndExpression only takes strings, so use the column struct
.AndExpression(Table1.Columns.FieldY).IsEqualTo("S")
.Or(Table1.FieldYColumn).IsEqualTo("T")
.ExecuteAsCollection();

Resources