Raised This Month: $ Target: $400
 0% 

SQL_TableExists help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 08-31-2009 , 17:32   SQL_TableExists help
Reply With Quote #1

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;

__________________

Last edited by minimiller; 08-31-2009 at 18:10. Reason: fix't
minimiller is offline
Send a message via MSN to minimiller
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-31-2009 , 17:41   Re: SQL_TableExists help
Reply With Quote #2

Little info, dunno if it work but syntax looks fine -> http://sqlserver2000.databases.aspfa...-database.html
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 08-31-2009 , 17:53   Re: SQL_TableExists help
Reply With Quote #3

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
__________________
minimiller is offline
Send a message via MSN to minimiller
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-31-2009 , 18:03   Re: SQL_TableExists help
Reply With Quote #4

Oh, then dunno, but yours looks fine too anyway...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-31-2009 , 18:05   Re: SQL_TableExists help
Reply With Quote #5

Why do you have a loop?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 08-31-2009 , 18:09   Re: SQL_TableExists help
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
Why do you have a loop?
an interesting question
the answer would be... ummmm... i have no idea

EDIT:
Fixed #1
__________________
minimiller is offline
Send a message via MSN to minimiller
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-31-2009 , 18:38   Re: SQL_TableExists help
Reply With Quote #7

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;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 08-31-2009 , 18:44   Re: SQL_TableExists help
Reply With Quote #8

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


thx
<3
__________________
minimiller is offline
Send a message via MSN to minimiller
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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