mysql_insert("INSERT INTO `znote_accounts` (`account_id`, `ip`, `created`, `active`, `active_email`, `activekey`, `flag`) VALUES ('$account_id', '$ip', '$created', '$active', '0', '$activeKey', '$flag')");
uint64_t IOLoginData::createAccount(std::string name, std::string password)
{
_encrypt(password, false);
Database* db = Database::getInstance();
DBQuery query;
query << "INSERT INTO `accounts` (`id`, `name`, `password`) VALUES (NULL, " << db->escapeString(name) << ", " << db->escapeString(password) << ")";
query << "INSERT INTO `znote_accounts` ((`id`, `id`, `0`, `0`, `0`, `0`, `1`, `0`, `0`,`0`,`0`) <<";
if(!db->query(query.str()))
return 0;
return db->getLastInsertId();
}
CREATE TABLE IF NOT EXISTS `znote_accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
`ip` bigint(20) UNSIGNED NOT NULL,
`created` int(10) NOT NULL,
`points` int(10) DEFAULT 0,
`cooldown` int(10) DEFAULT 0,
`active` tinyint(4) NOT NULL DEFAULT '0',
`active_email` tinyint(4) NOT NULL DEFAULT '0',
`activekey` int(11) NOT NULL DEFAULT '0',
`flag` varchar(20) NOT NULL,
`secret` char(16) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
uint64_t IOLoginData::createAccount(std::string name, std::string password)
{
_encrypt(password, false);
Database* db = Database::getInstance();
DBQuery query;
query << "INSERT INTO `accounts` (`id`, `name`, `password`) VALUES (NULL, " << db->escapeString(name) << ", " << db->escapeString(password) << ")";
if(!db->query(query.str()))
return 0;
uint64_t acc_id = db->getLastInsertId();
DBQuery z_query;
z_query << "INSERT INTO `znote_accounts` ( `account_id`, `ip`, `created`, `flag`) VALUES (" << acc_id << ", 0, 0, '')";
db->query(z_query.str());
return acc_id;
}
[20:40:39.003] mysql_real_query(): INSERT INTO `accounts` (`id`, `name`, `password`) VALUES (NULL, 'Knnnsd', '8817b72941bea095086cbf7549d30beecc43a78c')INSERT INTO `znote_accounts` ((`id`, `id`, `0`, `0`, `0`, `0`, `1`, `0`, `0`,`0`,`0`) << - MYSQL ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO `znote_accounts` ((`id`, `id`, `0`, `0`, `0`, `0`, `1`, `0`, `0`,...' at line 1 (1064)
[20:54:52.747] mysql_real_query(): INSERT INTO `accounts` (`id`, `name`, `password`) VALUES (NULL, 'Umsijsnjmd', 'bfbd330b1dac02060a6fd553d0f2f21b62792495') - MYSQL ERROR: Duplicate entry 'Umsijsnjmd' for key 'name' (1062)
Note: I don't really know much C++, but I believe it'd be something like this
C++:uint64_t IOLoginData::createAccount(std::string name, std::string password) { _encrypt(password, false); Database* db = Database::getInstance(); DBQuery query; query << "INSERT INTO `accounts` (`id`, `name`, `password`) VALUES (NULL, " << db->escapeString(name) << ", " << db->escapeString(password) << ")"; if(!db->query(query.str())) return 0; uint64_t acc_id = db->getLastInsertId(); DBQuery z_query; z_query << "INSERT INTO `znote_accounts` ( `account_id`, `ip`, `created`, `flag`) VALUES (" << acc_id << ", 0, 0, '')"; db->query(z_query.str()); return acc_id; }
-- Convert existing accounts in database to be Znote AAC compatible
INSERT INTO `znote_accounts` (`account_id`, `ip`, `created`, `flag`)
SELECT
`a`.`id` AS `account_id`,
0 AS `ip`,
UNIX_TIMESTAMP(CURDATE()) AS `created`,
'' AS `flag`
FROM `accounts` AS `a`
LEFT JOIN `znote_accounts` AS `z`
ON `a`.`id` = `z`.`account_id`
WHERE `z`.`created` IS NULL;
-- Delete duplicate account records
DELETE `d` FROM `znote_accounts` AS `d`
INNER JOIN (
SELECT `i`.`account_id`,
MAX(`i`.`id`) AS `retain`
FROM `znote_accounts` AS `i`
GROUP BY `i`.`account_id`
HAVING COUNT(`i`.`id`) > 1
) AS `x`
ON `d`.`account_id` = `x`.`account_id`
AND `d`.`id` != `x`.`retain`;
-- Convert existing players in database to be Znote AAC compatible
INSERT INTO `znote_players` (`player_id`, `created`, `hide_char`, `comment`)
SELECT
`p`.`id` AS `player_id`,
UNIX_TIMESTAMP(CURDATE()) AS `created`,
0 AS `hide_char`,
'' AS `comment`
FROM `players` AS `p`
LEFT JOIN `znote_players` AS `z`
ON `p`.`id` = `z`.`player_id`
WHERE `z`.`created` IS NULL;
-- Delete duplicate player records
DELETE `d` FROM `znote_players` AS `d`
INNER JOIN (
SELECT `i`.`player_id`,
MAX(`i`.`id`) AS `retain`
FROM `znote_players` AS `i`
GROUP BY `i`.`player_id`
HAVING COUNT(`i`.`id`) > 1
) AS `x`
ON `d`.`player_id` = `x`.`player_id`
AND `d`.`id` != `x`.`retain`;