SELECT имя_столбца1, имя_столбца2 FROM имя_таблицы WHERE условие, например имя_столбца3 = 3
UPDATE имя_таблицы SET имя_столбца1 = значение, имя_столбца2 = значение WHERE условие, например имя_столбца3 = 3
вставлять
INSERT INTO имя_таблицы (имя_столбца1, имя_столбца2) VALUES (значение , значение )
заменять уже имеющиеся данные
или INSERT OR REPLACE INTO а для mysql INSERT INTO + ON DUPLICATE KEY UPDATEИзменение:
PHP:UPDATE имя_таблицы SET имя_столбца1 = значение, имя_столбца2 = значение WHERE условие, например имя_столбца3 = 3
FormatEx(sQuery, sizeof(sQuery), "INSERT OR REPLACE INTO Names(steamid, name) VALUES('%s', '%s') WHERE steamid = '%s';", auth, arg2, auth);
SQL_FastQuery(g_SQL, sQuery);
А через UPDATE можно вносить данные?@TheSomeone, А разве не через "UPDATE таблица SET"
decl String:query[8192], String:buffer[MAX_STEAMID_LENGTH];
Format(query, sizeof(query), "UPDATE bublick SET %s WHERE steamid = '%s'", query, buffer);
Ну тут либо дебажить запрос который при добавлении будет проверять и заменять либо разделить на 2 запроса:
1. Поиск игрока в базе
2. Если есть - update, если нет - insert
if(SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
SQL_FetchString(hndl, 0, name, sizeof(name));
}
@TheSomeone, передавай его датапаком. хотя можно и из бд выбрать. дай кусок кода.
public Action:PlayerRename(iClient, args)
{
decl String:sQuery[256];
decl String:auth[36];
if (args < 1)
{
ReplyToCommand(iClient, "[ABp] Используй: sm_setname <#userid|ник> [новый ник]");
return Plugin_Handled;
}
decl String:arg[MAX_NAME_LENGTH], String:arg2[MAX_NAME_LENGTH];
GetCmdArg(1, arg, sizeof(arg));
if (args > 1)
{
GetCmdArg(2, arg2, sizeof(arg2));
}
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
iClient,
target_list,
MAXPLAYERS,
COMMAND_TARGET_NONE,
target_name,
sizeof(target_name),
tn_is_ml)) > 0)
{
if (tn_is_ml)
{
ShowActivity(iClient, "[SM] ", "%t", "Renamed target", target_name);
}
else
{
ShowActivity(iClient, "[SM] ", "%t", "Renamed target", target_name);
}
if (target_count > 1)
{
ReplyToCommand(iClient, "[ABp] Нет такого игрока!");
}
for (new i = 0; i < target_count; i++)
{
{
Format(g_NewName[target_list[i]], MAX_NAME_LENGTH, "%s", arg2);
}
PerformRename(iClient, target_list[i]);
GetClientAuthId(target_list[i],AuthId_Steam2,auth,sizeof(auth));
FormatEx(sQuery, sizeof(sQuery), "INSERT INTO Names(steamid, name) VALUES('%s', '%s');", auth, arg2, auth);
SQL_FastQuery(NamesDb, sQuery);
}
}
else
{
ReplyToTargetError(iClient, target_count);
}
return Plugin_Handled;
}
public Action:PlayerRename(iClient, args)
{
decl String:auth[36];
if (args < 1)
{
ReplyToCommand(iClient, "[ABp] Используй: sm_setname <#userid|ник> [новый ник]");
return Plugin_Handled;
}
decl String:arg[MAX_NAME_LENGTH], String:arg2[MAX_NAME_LENGTH];
GetCmdArg(1, arg, sizeof(arg));
if (args > 1)
{
GetCmdArg(2, arg2, sizeof(arg2));
}
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
iClient,
target_list,
MAXPLAYERS,
COMMAND_TARGET_NONE,
target_name,
sizeof(target_name),
tn_is_ml)) > 0)
{
if (tn_is_ml)
{
ShowActivity(iClient, "[SM] ", "%t", "Renamed target", target_name);
}
else
{
ShowActivity(iClient, "[SM] ", "%t", "Renamed target", target_name);
}
if (target_count > 1)
{
ReplyToCommand(iClient, "[ABp] Нет такого игрока!");
}
decl i, Handle:hDataPack, String:sQuery[256];
for (i = 0; i < target_count; i++)
{
strcopy(g_NewName[target_list[i]], MAX_NAME_LENGTH, arg2);
PerformRename(iClient, target_list[i]);
GetClientAuthId(target_list[i],AuthId_Steam2,auth,sizeof(auth));
hDataPack = CreateDataPack();
WritePackString(hDataPack, auth);
WritePackString(hDataPack, arg2);
FormatEx(sQuery, sizeof(sQuery), "SELECT steamid FROM Names WHERE steamid = '%s';", auth, arg2, auth);
SQL_TQuery(NamesDb, SQL_Callback_SelectClient, sQuery, hDataPack);
}
FormatEx(sQuery, sizeof(sQuery), "INSERT INTO Names(steamid, name) VALUES('%s', '%s');", auth, arg2, auth);
SQL_FastQuery(NamesDb, sQuery);
}
}
else
{
ReplyToTargetError(iClient, target_count);
}
return Plugin_Handled;
}
public SQL_Callback_SelectClient(Handle:hOwner, Handle:hQuery, const String:sError[], any:hDataPack)
{
if (sError[0])
{
LogError("SQL_Callback_SelectClient: %s", sError);
CloseHandle(hDataPack);
return;
}
decl String:sQuery[256], String:sName[MAX_NAME_LENGTH*2+1], String:auth[36];
ResetPack(hDataPack);
ReadPackString(hDataPack, auth, sizeof(auth));
ReadPackString(hDataPack, sQuery, sizeof(sQuery));
SQL_EscapeString(NamesDb, sQuery, sName, sizeof(sName));
CloseHandle(hDataPack);
if (SQL_FetchRow(hQuery))
{
FormatEx(sQuery, sizeof(sQuery), "UPDATE `Names` SET `name` = '%s' WHERE `steamid` = '%s';", sName, auth);
}
else
{
FormatEx(sQuery, sizeof(sQuery), "INSERT INTO Names (steamid, name) VALUES ('%s', '%s');", auth, sName);
}
SQL_TQuery(NamesDb, SQL_Callback_ErrorCheck, sQuery);
}
public SQL_Callback_ErrorCheck(Handle:hOwner, Handle:hQuery, const String:sError[], any:data)
{
if (sError[0])
{
LogError("SQL_Callback_ErrorCheck: %s", sError);
}
}