How can i solve this dont correct data? - mysql

flow.set("payload","msg.payload.payload");
flow.set("humidity","msg.payload.humidity");
var date = new Date().getTime();
msg.topic= "insert into sensor(temp, humidity, date) values('"+msg.payload.payload+"', '"+msg.payload.humidity+"', '"+date+"')";
return msg;
this is my function code
i receive data to {"_msgid":"81665f152edd9336","payload":"25.20","topic":"rpi-dht22","humidity":"39.30","isValid":true,"errors":2,"sensorid":"dht22"}
but saw in database undefined, undefined, 1636534958644
what is problem?

You have 2 problems with the function node.
Firstly you are inserting strings into the flow context rather than the values from the incoming message, you should not be wrapping the value argument in quotes.
Secondly you have an extra payload in the msg object keys.
It should probably look like this:
flow.set("payload",msg.payload);
flow.set("humidity",msg.humidity);
var date = new Date().getTime();
msg.topic= "insert into sensor(temp, humidity, date) values('"
+ msg.payload + "', '"
+ msg.humidity + "', '"
+ date + "')";
return msg;

Related

Attempt to invoke virtual method getDatabasePath(java.lang.String)' on a null object reference

what dos this error mean? and how can I fix it?
I am trying to save data into my database, but I want to check if there already data exist there. and if there is, I want to update it.
Thank you for your help! It will be highly appreciated!
LogCat:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference
at com.musicapp.android.musicapp.SQLDataBase.App_Theme_Color(SQLDataBase.java:220)
at com.musicapp.android.musicapp.Settings.ThemeCustomAdapter$1$1.run(ThemeCustomAdapter.java:50)
CODE:
public void App_Theme_Color(int color1, int color2, int color3) {
220 SQLiteDatabase db = this.getReadableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_01,color1);
contentValues.put(COL_0002,color2);
contentValues.put(COL_0003,color3);
String query = (" SELECT " + COL_01 + "," + COL_0002 + "," + COL_0003 + " FROM " + Table_Name3);
Cursor cursor = db.rawQuery(query,null);
if (cursor.getCount() > 0){
String updateQuery = (" UPDATE " + Table_Name3 + " SET " + COL_01 + " ='" + color1 + " '" + "," + COL_0002 + " ='" + color2 + " '" + "," + COL_0003 + " ='" + color3 + " '");
db.update(Table_Name3,contentValues," WHERE",null);
db.execSQL(query);
db.execSQL(updateQuery);
}else{
db.insert(Table_Name3,null,contentValues);
}
cursor.close();
db.close();
}
In your code at line 220, you cannot call getReadableDatabase on this, as getReadableDatabase is a method that belongs to the SQLiteOpenHelper class. You must instantiate an object of SQLiteOpenHelper, or some sub-class of it, and then call this method on that object.

Json object access in Node server

I am new to Node server. In my program I fetched some data from data base as
connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, rows)
{
var employees = (JSON.stringify(rows));
console.log("Inside server "+employees )
});
Now in console i got some thing like
[{"user_id":7,"username":"vb","password":"vbv"}]
Now my Question is how i could get the value username from employees. I have tried few things like
employees[0]["username"] OR employees.username etc..
Because you stringify it, it becomes string so you can't access like that. Just use it as is.
JSON.stringify(rows) only allow you to pretty print the data.
To access it you were right with employees[0]["username"]
connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, employees)
{
console.log("Inside server " + JSON.stringify(employees));
console.log('Employee 1: ' + employees[0]["username"]);
});

How to get dynamic object properties

I'm receiving a Json object from a request and I would like to Iterate over its properties and do something like:
if property is equals to "EN" than get it's value.
The solutions That I saw in the web are all related with GetProperties/GetProperty methods but I tried both and none of them worked.
This should be something "simple" but I think that I'm missing something here.
//Deserializing the object
ExpandoObject deserializedContent = JsonConvert.DeserializeObject<ExpandoObject>(obj.ToString(), new ExpandoObjectConverter());
dynamic deserializedDynamicContent = deserializedContent;
//Tries
var value = deserializedDynamicContent.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
var value = deserializedDynamicContent.GetType().GetProperty("ES").GetValue();
in both cases I get zero properties.
I can only get the values if I do the code below, but this will obly me to code if a new language is added.
deserializedDynamicContent.EN,
deserializedDynamicContent.ES or
deserializedDynamicContent.PT
What Am I doing wrong here?
{
"EN":[{"Id":1,"Name":"One"},{"Id":2,"Name":"Two"},{"Id":3,"Name":"Tree"}],
"ES":[{"Id":1,"Name":"Uno"},{"Id":2,"Name":"Dos"},{"Id":3,"Name":"Tres"}],
"PT":[{"Id":1,"Name":"Um"},{"Id":2,"Name":"Dois"},{"Id":3,"Name":"TrĂªs"}]
}
I'm not sure exactly what you're trying to achieve, but since ExpandoObject implements IDictionary<string,object> you should be able to do something like this:
var expando = JsonConvert.DeserializeObject<ExpandoObject>(yourJson);
var dict = (IDictionary<string, object>)expando;
// look for a particular key...
object value;
if (dict.TryGetValue("EN", out value))
{
Console.WriteLine("Key exists!");
var list = (List<dynamic>)value;
Console.WriteLine(string.Join(",", list.Select(x => "{" + x.Id + "," + x.Name + "}")));
}
// or enumerate the entire dictionary...
foreach (var kvp in dict)
{
var list = (List<dynamic>)kvp.Value;
Console.WriteLine(
kvp.Key + ":" + string.Join(",", list.Select(x => "{" + x.Id + "," + x.Name + "}")));
}

Create SSRS subscriptions from web page

I have Reporting Services running on SQL 2008 R2 and have a handful of reports that I created. I'm able to go into Report Server and set up a subscription and have any of the reports emailed to an email address. So all of that is configured correctly.
What I want to do is have a web page in my application that shows a list of available reports. The user can choose one, choose a schedule frequency, enter an email address, and click a 'save' button. When clicking save it should create the subscription in SSRS. I may need to pass in a couple report parameters depending on the report.
How can I do this in C#?
You can dynamically generate a one time subscription in SSRS for the report. You'll have to use the RS webservice as mentioned by Diego.
Your code would look something like this:
static void generateSubscription()
{
if (SubscriptionRequests.Count < 1) return;
NetworkCredential credentials = new NetworkCredential("user", "pass");
reports.ReportingService2005 rs = new reports.ReportingService2005();
rs.Credentials = credentials;
DateTime topDatetime = DateTime.Now;
topDatetime = topDatetime.AddMinutes(2);
foreach (SubscriptionRequest x in SubscriptionRequests)
{
reports.ExtensionSettings extensionSettings = new reports.ExtensionSettings();
List<reports.ParameterValue> extParameters = new List<reports.ParameterValue>();
List<reports.ParameterValue> parameters = new List<reports.ParameterValue>();
string description = "Email: ";
string eventType = "TimedSubscription";
extensionSettings.Extension = "Report Server Email";
string scheduleXml = "<ScheduleDefinition><StartDateTime>";
scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
scheduleXml += "</StartDateTime></ScheduleDefinition>";
parameters.Add(new reports.ParameterValue() { Name = "abc", Value = x.id });
extParameters.Add(new reports.ParameterValue() { Name = "RenderFormat", Value = x.renderFormat });
extParameters.Add(new reports.ParameterValue() { Name = "TO", Value = x.email });
extParameters.Add(new reports.ParameterValue() { Name = "ReplyTo", Value = x.replyTo });
extParameters.Add(new reports.ParameterValue() { Name = "IncludeReport", Value = "True" });
extParameters.Add(new reports.ParameterValue() { Name = "Subject", Value = "subject - " + " (" + x.id.ToString() + ")" });
extParameters.Add(new reports.ParameterValue() { Name = "Comment", Value = x.body });
extensionSettings.ParameterValues = extParameters.ToArray();
description += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
description += " (" + x.a + " - " + x.b + " - " + x.c + ")";
string _reportName = "/report";
rs.CreateSubscription(_reportName, extensionSettings, description, eventType, scheduleXml, parameters.ToArray());
topDatetime = topDatetime.AddSeconds(30);
}
}
Easiest way is give access to the user to the report manager under the "Browser" pre-defined role. This is exactly what this role is about, view folders and reports and subscribe to reports.
If that's not possible you can create your own management tool. To do that you need to access the SSRS web methods Using SOAP and the ReportService2005 endpoint
Examples here

Update jqGrid table with the results of Fusion Tables query in a Google Maps v3 page

I am looking to understand how to update a jqGrid table from Fusion Tables (FT) -
at the moment I can search or scroll on a Google Map, send an event listener that compiles a FT query of the spatial bounds of the viewport/map, to get a new set of results.
I want to use the new FT query string (or could use the Google code to retrieve the data - query.send(getData);) to update the jqGrid table with the new values.
Before I started using jqGrid, I tried/suceeded with the Google Visualisation API, and some of that code is below. Could anyone suggest how to move from table.draw, to loading/reloading a jqGrid table? Thanks a lot in advance.
function tilesLoaded() {
google.maps.event.clearListeners(map, 'tilesloaded');
google.maps.event.addListener(map, 'zoom_changed', getSpatialQuery);
google.maps.event.addListener(map, 'dragend', getSpatialQuery);
getSpatialQuery();
}
function getSpatialQuery() {
sw = map.getBounds().getSouthWest();
ne = map.getBounds().getNorthEast();
var spatialQuery = "ST_INTERSECTS(latitude, RECTANGLE(LATLNG(" + sw.lat() + "," + sw.lng() + "), LATLNG(" + ne.lat() + "," + ne.lng() + ")))";
changeDataTable(spatialQuery);
}
function changeDataTable(spatialQuery) {
var whereClause = "";
if(spatialQuery) {
whereClause = " WHERE " + spatialQuery;
}
var queryText = encodeURIComponent("SELECT 'latitude', 'longitude', 'name' FROM xxxxxxxx" + whereClause + " LIMIT 50");
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
query.send(getData);
}
function getData(response) {
var table = new google.visualization.Table(document.getElementById('visualization'));
table.draw(response.getDataTable(), {showRowNumber: true});
}
Oh, and I used Oleg's code jqGrid returns blank cells as a basis for just seeing if I could get a simple multi-select table to pull data from my FT - that worked fine with the simple mod of
url: 'http://www.google.com/fusiontables/api/query?sql=' +
In case this helps someone, I've taken some of the code I came up with and pasted it below:
// You can get the map bounds via then pass it via a function (below is hacked from several functions
sw = map.getBounds().getSouthWest();
ne = map.getBounds().getNorthEast();
var whereClause = "ST_INTERSECTS(latitude, RECTANGLE(LATLNG(" + sw.lat() + "," + sw.lng() + "), LATLNG(" + ne.lat() + "," + ne.lng() + ")))";
//construct the URL to get the JSON
var queryUrlHead = 'http://www.google.com/fusiontables/api/query?sql=';
var queryUrlTail = '&jsonCallback=?'; //
var queryOrderBy = ' ORDER BY \'name\' ASC';
var queryMain = "SELECT * FROM " + tableid + whereClause + queryOrderBy + " LIMIT 100";
var queryurl = encodeURI(queryUrlHead + queryMain + queryUrlTail);
//use the constructed URL to update the jqGrid table - this is the part that I didn't know in my above question
$("#gridTable").setGridParam({url:queryurl});
$("#gridTable").jqGrid('setGridParam',{datatype:'jsonp'}).trigger('reloadGrid');