Welcome Soldier.



[ SQL ] Crear Tablas

ChrstopH Ausente
Hypnotize
#1
kpx, es un plugin que hice hace unos minutos xdXdXDxddxDXXDxd

Consiste en que puedan su tabla desde un archivo .ini

Uso:
- Crear un archivo .ini en configs llamado "Tablas"
- dentro de el meten el script para crear su tabla
- En el .sma Ponen el nombre de su DB ( es decir el del archivo sq3 )
- Una ves ya teniendo lo anterior escriben "amx_tabla" en consola y debería crearse  :whatever:

PD; Ya se que es un plugin muy simple, tal ves a alguien le sirva :whatever:

 
Código PHP:
<?php 
/* Script generated by Pawn Studio */

#include <amxmodx>
#include <amxmisc>
#include <sqlx>

new const szArchivo[] = "Tablas.ini";

new const
szDB[] = "TEST"; // cambiar al nombre de tu DB ( osea el archivo sq3 )

new szRuta[ 300 ]; 
new szPath[ 256 ];

new
Handle:hTuple;

public
plugin_init()
{
register_plugin("Crear Tablas SQL", "0.1", "Hypnotize");
// Add your own code here

get_configsdir( szPath, charsmax( szPath ) );
formatex( szRuta, charsmax( szRuta ), "%s/%s", szPath, szArchivo );

register_clcmd("amx_tabla", "LeerIni");

MySQLx_Init();
}

public
LeerIni( id )
{
if( ~
get_user_flags( id ) & ADMIN_RCON )
{
client_print( id, print_chat, "[ AMXX ] No tienes acceso a este comando!" );
return;
}
if( !
file_exists( szRuta ) ) 
{
client_print( id, print_console, "[ AMXX ] El archivo '%s' NO Existe.", szRuta );
return;
}

new
szLine[ 700 ], szTable[ 1000 ], len = 0;
new
file; file = fopen( szRuta, "r" );

while(
file && !feof( file ) )
{
fgets( file, szLine, charsmax( szLine ) );

if(
szLine[ 0 ] == ';' || szLine[ 0 ] == '/' && szLine[ 1 ] == '/' || !szLine[ 0 ] )
continue;

len += format( szTable[len], charsmax( szTable ) - len, "%s", szLine );
}

fclose( file );

SQL_ThreadQuery( hTuple, "QueryCreateTable", szTable );
}
 
public MySQLx_Init()
{
    new get_type[ 12 ]; SQL_SetAffinity( "sqlite" );
    SQL_GetAffinity( get_type, sizeof get_type );

    if( !equali( get_type, "sqlite" ) )
    {
        log_to_file( "SQLITE_ERROR.txt", "[ AMXX ] Error de conexion" );
        return pause( "a" );
    }
    
    hTuple
= SQL_MakeDbTuple( "", "", "", szDB );
    
   
return PLUGIN_CONTINUE
}

public
plugin_end( )
SQL_FreeHandle( hTuple ); 

public QueryCreateTable(failstate, error[], error2, data[], size, Float:queuetime)
{
    switch ( failstate )
    {
        case TQUERY_CONNECT_FAILED: log_to_file("SQL_LOG_TQ.txt", "Failed to connect to database [%i]: %s", error2, error)
        case TQUERY_QUERY_FAILED: log_to_file("SQL_LOG_TQ.txt", "Error on query for creating table [%i]: %s", error2, error)
    }
    
   
return PLUGIN_HANDLED;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
*/

IMAGENES:
Tabla a crear en .ini
[ http://prntscr.com/lp8x48 ]

Tabla creada y revisada:

[ http://prntscr.com/lp8wzi ]
[Imagen: 76561198283253977.png]

Mapas Frutas 100%
DeathRun Levels 100%
Atrapa al Traidor (Edición) 100%
Battle Royale 40%
[+] 1 user says Thank You to ChrstopH for this post
Responder

GabsHp Sin conexión
Lord Gabs
#2
No entendí cuál es la función Xd Crear una tabla con un string ya definido en un .ini, activado mediante un comando de amx? Eso entendí, no sé si eso era o estoy pacheco Xd
Responder

ChrstopH Ausente
Hypnotize
#3
Por si eres wey y no tenes el SQLManager y ocupas crear una tabla para algún plugin, metes el script para crear la tabla en el .ini y pones amx_tabla y te ejecuta el script creandote la tabla en la DB :whatever:
[Imagen: 76561198283253977.png]

Mapas Frutas 100%
DeathRun Levels 100%
Atrapa al Traidor (Edición) 100%
Battle Royale 40%
Responder





Usuarios navegando en este tema:



Sobre M X E M E X I C O

Comunidad MxE © 2020 - La mejorar comunidad de Counter Strike 1.6 .