In STL maps, is it better to use map::insert than []?

When you write map[key] = value; there’s no way to tell if you replaced the value for key, or if you created a new key with value. map::insert() will only create: using std::cout; using std::endl; typedef std::map<int, std::string> MyMap; MyMap map; // … std::pair<MyMap::iterator, bool> res = map.insert(MyMap::value_type(key,value)); if ( ! res.second ) { cout … Read more

Which is faster: multiple single INSERTs or one multiple-row INSERT?

https://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html The time required for inserting a row is determined by the following factors, where the numbers indicate approximate proportions: Connecting: (3) Sending query to server: (2) Parsing query: (2) Inserting row: (1 × size of row) Inserting indexes: (1 × number of indexes) Closing: (1) From this it should be obvious, that sending one … Read more

Escaping single quote in PHP when inserting into MySQL [duplicate]

You should be escaping each of these strings (in both snippets) with mysql_real_escape_string(). http://us3.php.net/mysql-real-escape-string The reason your two queries are behaving differently is likely because you have magic_quotes_gpc turned on (which you should know is a bad idea). This means that strings gathered from $_GET, $_POST and $_COOKIES are escaped for you (i.e., “O’Brien” -> … Read more

Export specific rows from a PostgreSQL table as INSERT SQL script

Create a table with the set you want to export and then use the command line utility pg_dump to export to a file: create table export_table as select id, name, city from nyummy.cimory where city = ‘tokyo’ $ pg_dump –table=export_table –data-only –column-inserts my_database > data.sql –column-inserts will dump as insert commands with column names. –data-only … Read more

How do I use an INSERT statement’s OUTPUT clause to get the identity value?

You can either have the newly inserted ID being output to the SSMS console like this: INSERT INTO MyTable(Name, Address, PhoneNo) OUTPUT INSERTED.ID VALUES (‘Yatrix’, ‘1234 Address Stuff’, ‘1112223333’) You can use this also from e.g. C#, when you need to get the ID back to your calling app – just execute the SQL query … Read more

INSERT IF NOT EXISTS ELSE UPDATE?

Have a look at http://sqlite.org/lang_conflict.html. You want something like: insert or replace into Book (ID, Name, TypeID, Level, Seen) values ((select ID from Book where Name = “SearchName”), “SearchName”, …); Note that any field not in the insert list will be set to NULL if the row already exists in the table. This is why … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)