set query into response bot microsoft framework - sql

Team I'm trying to set the answer query in an answer into bot microsoft framework
This is what I do:
request = new Request(
"Here the string that returns me a number for example 763",
function(err, rowCount, rows)
{
console.log(rowCount + ' row(s) returned');
process.exit();
}
);
request.on('row', function(columns) {
columns.forEach(function(column) {
**session.send(column.value);
next();**
});
});
connection.execSql(request);
The consult is ok, but I get the error :
cannot create property 'type' on number
For me Session.send is the way to send a message to the user from bot framewok emulator.

Error - in Sql query syntax erorr:
"SELECT Medicina.Nombre FROM Medicina where='Aspirina'"
Change column name below query:
"SELECT Medicina.Nombre FROM Medicina where column_name='Aspirina'"

Related

How to insert a username if it doesn't already exist with a postgresql POOL query

I am making a game and I recently added a server database score saver but I can't figure out how to insert a username only if it doesn't already exist here is the following query:
const addUser = (req, res) => {
const {username, score} = req.body;
pool.query(
'INSERT INTO userlist (username, score) VALUES ($1, $2)',
[username, score],
(err) => {
if(err){
throw err;
}
res.status(201).json({status: "success", message: "User added."});
},
);
}
I am guessing I'll have to change the query
also here is my SQL code for creating the table:
CREATE TABLE userlist(
ID SERIAL PRIMARY KEY,
username VARCHAR(255),
score VARCHAR(255)
);
The best way to handle this is to let the database validate the uniqueness of the username:
alter table userlist add constraint unq_userlist_usename unique(username);
Now if you attempt to insert a single row, then it will return an error if the row already exists.
If you don't want an error you can use an on conflict clause. However, in this case, an exception seems useful to notify the user that username already exists.
use an if statement to identify if the username exist and then update it
if (Users::where('name', $request->user_name)->exists()) {
return response()->json(['record exist']);
} else {
$save = new Users;
$save->name = $request->user_name;
$save->save();
return response()->json(['User saved successfully.']);
}

How to order queries in sql in flutter?

I am using sqlite database in Flutter. with provide and sqlite libraries. I want to get ordered list of String in the database when I get the list from sqlite. How can I achieve this? Thank you for your response!
You can use orderBy variable inside query method like this:
Future<List<SingleShiftModel>> getShiftModelsForParticularGroup(
String groupId) async {
Database db = await database;
final List<Map<String, dynamic>> maps = await db.query(
allShiftsTableName,
where: 'parentId = ?',
orderBy: "date ASC", // here you can add your custom order exactly like sqlite but EXCLUDE `ORDER BY`.
whereArgs: [groupId],
);
return List.generate(
maps.length,
(i) => SingleShiftModel.toShiftModelObject(maps[i]),
);
}

NODE JS Passing characters in get request

I am using Node and Express with MSNODESQLV8 to write an API demo (my first) to get some rows from a remote SQL Server instance. My other get queries work fine when searching for an ID which is a number but I am unsure how to pass a value in the form of characters to a parameter in my query. Pretty sure req.params.id is not appropriate.
app.get("/productsname/:id", (req, res) => {
const productName = req.params.id;
const productsNameQuery = "SELECT * FROM Products WHERE ProductName = ?";
sql.query(connStr, productsNameQuery, [productName], (err, rows) => {
if (err) {
console.log(`Failed to get product by id ${req.params.id}. ${err}`);
res.sendStatus(500);
}else {
res.json(rows);
}
})
});
I want to take a product name (string?) in at the end of the url where it reads "id" and pass it as a value to the productName const. The end goal is to retrieve all rows from the SQL table where the product name is "processor" in the get url (http://localhost:2000/productname/proccesor). Perhaps I am passing the url incorrectly?
Apologies if this is really basic. I am very new to this.
Thanks in advance

Laravel DB::update don't working, doing nothing at all, without any errors

I am learning how to run raw SQL queries and stuck at UPDATE operation.
I have route for INSERT:
Route::get('/insert', function (){
DB::insert('insert into posts (title, content) values (?, ?)', ['PHP with Laravel', 'Just testing']);
return 'after insert';
});
And route for SELECT:
Route::get('/read', function (){
$results = DB::select('select * from posts');
return var_dump($results);
});
After SELECT query I see:
/home/pavel/www_mysite/TestLaravel/routes/web.php:31:
array (size=1)
0 =>
object(stdClass)[239]
public 'id' => int 11
public 'title' => string 'PHP with Laravel' (length=16)
public 'content' => string 'Just testing' (length=12)
public 'created_at' => null
public 'updated_at' => null
public 'is_admin' => int 0
And at least UPDATE query:
Route::get('/update', function (){
DB::update('update posts set title = "Nothing here"');
});
After that query the new SELECT query shows the same data and in PHPPgAdmin I found no changes. I installed LaravelDebugBar and may see it at the bottom of the browser at pages for INSERT and SELECT queries, but don't see it at the page for UPDATE query. I cannot realize, where is the mistake.
try to use where clause.
example :
$affected = DB::update('update users set votes = 100 where name = ?', ['John']);
I tested you code too and it work
see this picture
I run your update code on my local environment (laravel 5.2, mysql 5.1). It's updated OK.
How about your log?
After some extra research I found that PostrgreSQL may store case-sensitive names of tables and columns. For that case you need to take their names in double quotes in your query. I think that when PostrgreSQL found double quotes in the query - it "thinks" that it is table/column name. But there is no column with those name.

Get all classes in Parse-server

I'm writing a backup job, and need to fetch all classes in Parse-server, so I can then query all rows and export them.
How do I fetch all classes?
Thanks
Query the schemas collection.
GET /parse/schemas
Probably need to use the masterkey on the query. Not sure what language you're writing your job in but should be simple for you to create a REST query or create a node.js script and use the javascript/node api
--Added after comment below --
var Parse = require('parse/node').Parse;
Parse.serverURL = "http://localhost:23740/parse";
Parse.initialize('APP_ID', 'RESTKEY', 'MASTERKEY');
var Schema = Parse.Object.extend("_SCHEMA");
var query = new Parse.Query(Schema);
query.find({
success : (results) => {
console.log(JSON.stringify(results));
},
error : (err) => {
console.log("err : " + JSON.stringify(err));
}});