AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL_TableExists help (https://forums.alliedmods.net/showthread.php?t=102311)

minimiller 08-31-2009 17:32

SQL_TableExists help
 
Heya
This appears to work, but does any1 know any way to make it better?
its a bit sloppy atm and i wanna clean it up
PHP Code:

bool:SQL_TableExists(szTable[])
{
    new 
Handle:SqlConnection SQL_Connect(gSqlTupleErrorCodegError511);
    
    if(
SqlConnection == Empty_Handle)
    {
        
set_fail_state(gError);
    }
    
    new 
Handle:Query;
    new 
iOutput;
    
    
Query SQL_PrepareQuery(SqlConnection"SELECT * from `%s`"szTable);
    
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QuerygError511);
        
        if(
containi(gError"#1146") != -1)
        {
            
iOutput 0;
        }
        else if(
containi(gError"No result set in this query!") != -1)
        {
            
iOutput 0;
        }
    }
    else
    {
        
iOutput 1;
    }
    
    
SQL_FreeHandle(Query);
    
SQL_FreeHandle(SqlConnection);
    
    return 
iOutput == true:false;



Alka 08-31-2009 17:41

Re: SQL_TableExists help
 
Little info, dunno if it work but syntax looks fine -> http://sqlserver2000.databases.aspfa...-database.html

minimiller 08-31-2009 17:53

Re: SQL_TableExists help
 
LOL
thats the first site i went to when i tried to initially make the function
it didnt work though
i got some crazy errors that i cant remember

Alka 08-31-2009 18:03

Re: SQL_TableExists help
 
Oh, then dunno, but yours looks fine too anyway...

Exolent[jNr] 08-31-2009 18:05

Re: SQL_TableExists help
 
Why do you have a loop?

minimiller 08-31-2009 18:09

Re: SQL_TableExists help
 
Quote:

Originally Posted by Exolent[jNr] (Post 919349)
Why do you have a loop?

an interesting question
the answer would be... ummmm... i have no idea

EDIT:
Fixed #1

Exolent[jNr] 08-31-2009 18:38

Re: SQL_TableExists help
 
PHP Code:

bool:SQL_TableExists(szTable[])
{
    new 
Handle:SqlConnection SQL_Connect(gSqlTupleErrorCodegError511);
    
    if(
SqlConnection == Empty_Handle)
    {
        
set_fail_state(gError);
    }
    
    new 
Handle:Query;
    new 
iOutput 1;
    
    
Query SQL_PrepareQuery(SqlConnection"SELECT * from `%s`"szTable);
    
    if(!
SQL_Execute(Query))
    {
        
SQL_QueryError(QuerygError511);
        
        if(
containi(gError"#1146") != -1
        
|| containi(gError"No result set in this query!") != -1)
        {
            
iOutput 0;
        }
    }
    
    
SQL_FreeHandle(Query);
    
SQL_FreeHandle(SqlConnection);
    
    return 
bool:iOutput;



minimiller 08-31-2009 18:44

Re: SQL_TableExists help
 
i like it
allthough i cant actually remember what the error #1146 is so i might take it out


thx
<3


All times are GMT -4. The time now is 15:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.