question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insert operation is not inserting data properly

See original GitHub issue

Hi, I am facing a problem. I have a messenger application. i am sending messages using socket.io. If i type a message slowly and emit it’s working fine. But if i type several message quickly and send it to socket emit the out put is something like this

3048 : asd 3049 : asd 3056 : d 3056 : d 3056 : d 3056 : d 3056 : d 3056 : d 3056 : d 3062 : das 3062 : das 3062 : das 3062 : das 3062 : das 3062 : das 3071 : as 3071 : as 3072 : asd 3072 : asd 3072 : asd 3072 : asd 3072 : asd 3072 : asd 3072 : asd 3072 : asd 3076 : das 3076 : das 3076 : das 3076 : das

code is

await sMM.Im_message_Model.insert(senderId, receiverId, message, fileType, null, receiverType, date, time, date_time);

let fullMessage = await sMM.Im_message_Model.getRecentMessageWithUpdate(receiverId);

console.log(fullMessage.m_id+" : "+fullMessage.message);

Functions:

Im_message_Model.getRecentMessageWithUpdate = async (g_id)=>{
    let query="select * from im_message where receiver=? order by m_id DESC LIMIT 1";
    let [result,err]=await mysqlCon.execute(query,[g_id]);
    if(result.length>0){
        let prepareData=result[0];
        prepareData.poster="";
        if(prepareData.type!="text" && prepareData.type!="update" && prepareData.type!="document"){
            prepareData.message= baseUrl+"assets/im/group_"+g_id+"/"+prepareData.message;
        }
        if(prepareData.type=="document"){
            let fileUrl=encodeURIComponent(baseUrl + "assets/im/group_"+prepareData.receiver+"/"+prepareData.message)+"&fn="+encodeURIComponent(prepareData.fileName);
            prepareData.message=baseUrl+"download?f="+fileUrl;
        }
        if(prepareData.type=="video"){
            prepareData.poster=baseUrl+"assets/img/poster.jpg";
        }
        return prepareData;
    }
};

Im_message_Model.insert= async (u_id,g_id,message,type,fileName,receiver_type,date,time,date_time)=>{
    let query="INSERT INTO im_message (sender,receiver,message,type,fileName,receiver_type,date,time,date_time) VALUES (?,?,?,?,?,?,?,?,?)";
    await mysqlCon.execute(query,[u_id,g_id,message,type,fileName,receiver_type,date,time,date_time]);
};

m_id is unique and auto increment primary key.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fzp01717commented, Jul 16, 2018

Hi, This is my db picture. captureimg I am using pool. mysql2.createPool(database.dbSettings());

module.exports = {
    dbSettings: function () {
        return {
            connectionLimit: 300,
            host: '127.0.0.1',
            user: 'root',
            password: 'root',
            database: 'im_messenger'
        };
    }
};

do i need to release the pool connection after every query execution? New to node js. Don’t know how to enable debug option on connection. Can you help me in this ?

0reactions
fzp01717commented, Jul 16, 2018
console.log("---------------------Start---------------------------------");
let messageID=await sMM.Im_message_Model.insert(senderId, receiverId, message, fileType, null, receiverType, date, time, date_time);
let fullMessage = await sMM.Im_message_Model.getRecentMessageWithUpdate(receiverId);
console.log(fullMessage.m_id+" : "+fullMessage.message+" : "+messageID);
console.log("---------------------End---------------------------------");

log.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

insert query is giving no error but is not inserting in the database
One thing to check is to see if the table has a trigger. An instead of trigger could be overruling your insert. The...
Read more >
INSERT Operations That Are Not Valid - Teradata Database
INSERT Operations That Are Not Valid An INSERT operation causes an error or failure message to be returned if any of the following...
Read more >
Methods to Insert Data into SQL Server
Insert Data SQL Server with OUTPUT INSERTED ... WHERE account_type = 'LIVE';. SELECT * FROM #account_ids;. DROP TABLE #account_ids;. The results ...
Read more >
4. Inserting, Updating, Deleting - SQL Cookbook [Book] - O'Reilly
Simply follow the INSERT statement with a query that returns the desired rows. If you want to copy all rows from the source...
Read more >
Bulk Insert Task - SQL Server Integration Services (SSIS)
If the text file is located on the same computer as the SQL Server database into which data is inserted, the copy operation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found