Thanks! you saved the day!
Best posts made by malky shlomowith
Latest posts made by malky shlomowith
-
RE: why is the function LAST_INSERT_ID() not working for me
Thank you !!!
This was a big help!!
-
why is the function LAST_INSERT_ID() not working for me
I want to use the ID that was generated for one table and insert it into a second table and i am getting an error.
error: "SQL Syntax Error near 'INSERT INTO all_tokens (user_id, device, token)\n" +
" VALUES (LAST_' at line 3",let sql = `INSERT INTO users (name, nickname, email, password, last_logged, current_token ) VALUES ('${name}', '${nickname}', '${email}', '${hachPassword}',now(), '${token}' ) INSERT INTO all_tokens (user_id, device, token) VALUES (LAST_INSERT_ID(), '1' ,'${token}')` await cloudbackend.sqlExecuteRawQuery(sql).then(async res => { let result = await JSON.parse(res); console.log(result) if (result.affectedRows == 2 ) { // do something
}
-
RE: Try button is not working
yes I duplicatedthe function and it is stil not working.
The only thing that works is what i rwote in the past. The try does not responed to the updats i made in the code.
(the api function is a register api.) -
Try button is not working
Hi!
My try button is not working (it is working in the doc.). olso when i send a request from my front end it returns not fond.
Please help!
-
RE: Regster API Function.
@Wassim said in Regster API Function.:
how many rows have been affected in the return of sqlExecuteRawQuery
how do I check it?
-
RE: Regster API Function.
Hi!
Thanks for you answer!
I tried setting the email column as unique and this it the error I am getting:Error: Specified key was too long; max key length is 767 bytes
{"m_MaxCapacity":2147483647,"Capacity":1768,"m_StringValue":"ALTER TABLE
my-recipe-app-1fe491
.users
CHANGE COLUMNid
id
int AUTO_INCREMENT COMMENT '::' FIRST ;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNname
name
varchar(255) COMMENT '::' AFTERid
;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNnickname
nickname
varchar(255) COMMENT '::' AFTERname
;
ALTER TABLEmy-recipe-app-1fe491
.users
ADD UNIQUE INDEXemail_UNIQUE
(email
ASC);
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNemail
email
varchar(200) COMMENT 'email::' AFTERnickname
;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNpassword
password
varchar(255) COMMENT 'password::' AFTERemail
;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNdate_joined
date_joined
date COMMENT '::' AFTERpassword
;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNactive
active
int DEFAULT '0' COMMENT '::' AFTERdate_joined
;
ALTER TABLEmy-recipe-app-1fe491
.users
CHANGE COLUMNtoken
token
varchar(255) COMMENT '::' AFTERactive
;
","m_currentThread":0} -
Regster API Function.
This function I wrote does not always give me the token. (It does work sometimes)
This is the message I receive:"errorMessage": "Cannot read property '0' of undefined",
This is the fusction :
const cloudbackend = require('appdrag-cloudbackend'); cloudbackend.init(process.env.APIKEY, process.env.APPID); const bcrypt = require('bcrypt'); const uuid = require('uuid'); exports.handler = async(event, context, callback) => { let name = event["POST"]["name"]; let nickname = event["POST"]["nickname"]; let email = event["POST"]["email"]; let password = event["POST"]["password"]; let hachPassword = bcrypt.hashSync(password, 10); //Check email does not exists. let finedEmai = `SELECT email FROM users WHERE email = '${email}' ` await cloudbackend.sqlSelect(finedEmai).then(async res => { let result = JSON.parse(res); if (result.Table == null) { // Add user to DB. let sql = `INSERT INTO users (name, nickname, email, password, date_joined, token) VALUES ('${name}', '${nickname}', '${email}','${hachPassword}', now() , uuid())`; await cloudbackend.sqlExecuteRawQuery(sql).then(async res => { // Get current users token let cotentToken = `SELECT token FROM users WHERE id = LAST_INSERT_ID()` await cloudbackend.sqlSelect(cotentToken).then(async res => { let result = await JSON.parse(res); let token = result.Table[0] callback(null, token); }); }); } else { callback(null, result.Table[0]) } }) }