Raised This Month: $ Target: $400
 0% 

SQL column.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 01-09-2013 , 09:36   SQL column.
Reply With Quote #1

hello evreyone,

this code is open the table "psher" and 9 Columns.
PHP Code:
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS psher( steamid varchar(32), name varchar(32), column1 SMALLINT(1), column2 SMALLINT(1), column3 SMALLINT(1), column4 SMALLINT(1), column5 SMALLINT(1), column6 SMALLINT(1),column7 SMALLINT(1), column8 SMALLINT(1), column9 SMALLINT(1))"
and i thought to do it like this:
PHP Code:
new const tablenames[] = 
{
    
"column1",
    
"column2",
    
"column3",
    
"column4",
    
"column5",
    
"column6",
    
"column7",
    
"column8",
    
"column9"    
}
        
    for(new 
09i++)
    {
        
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS psher( steamid varchar(32), name varchar(32), %s SMALLINT(1))"tablenames[i])
    } 
but there is a problem i thinks because "CREATE TABLE IF NOT EXISTS" and table is already exists so its won't open another column..
someone has an idea how i can do this in my way( array ) , How to make it work?

thanks for helping
Mr.Waffle is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-09-2013 , 10:20   Re: SQL column.
Reply With Quote #2

You have to list each column out as you have in the first code snippet, you cannot do what you are thinking.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 01-09-2013 , 10:25   Re: SQL column.
Reply With Quote #3

OK, maybe there is another way to do it ? cuz i need to open like 30 column , and its really bad to write them 1 by one 1.

Last edited by Mr.Waffle; 01-09-2013 at 10:30.
Mr.Waffle is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-09-2013 , 10:27   Re: SQL column.
Reply With Quote #4

Use a for loop to add the columns to a formatted string and then pass that formatted string to SQL_PrepareQuery.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 01-09-2013 , 11:21   Re: SQL column.
Reply With Quote #5

somting like this : ?
PHP Code:
new const tablenames[] = 
{
    
"column1",
    
"column2",
    
"column3",
    
"column4",
    
"column5",
    
"column6",
    
"column7",
    
"column8",
    
"column9"    
}



    new 
szText[2048]
    for(new 
09i++)
    {   
        
format(szTextcharsmaxszText ),"CREATE TABLE IF NOT EXISTS expmod( %s SMALLINT(1))"tablenames[i])
    }
    
Queries SQL_PrepareQuery(SqlConnection,"%s"szText
Mr.Waffle is offline
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-09-2013 , 11:39   Re: SQL column.
Reply With Quote #6

no.

you should to format inside loop only tables one by one.

%s smallint(1), %s smallint(1), ...
PHP Code:
new szText[2048];
new 
szMotdHeader[] = "CREATE TABLE IF NOT EXISTS expmod(";
new 
iLen=0;
for(new 
i=0;i<9;i++)
   
iLen += formatexszText[iLen], charsmax(szText)-iLen"%s smallint(1)%s"tablenames[i],(i==8)?"":",");
iLen+=formatex(szText[iLen], charsmax(szText)-iLen")");
Queries SQL_PrepareQuery(SqlConnection,"%s",szText); 


and also:

Queries = SQL_PrepareQuery(SqlConnection,"%s",szText);
Queries = SQL_PrepareQuery(SqlConnection, szText);
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT

Last edited by AngeIII; 01-09-2013 at 11:40.
AngeIII is offline
Send a message via Skype™ to AngeIII
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-09-2013 , 11:43   Re: SQL column.
Reply With Quote #7

Has nobody checked the link I gave...
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 01-09-2013 , 12:11   Re: SQL column.
Reply With Quote #8

Quote:
Originally Posted by YamiKaitou View Post
Has nobody checked the link I gave...
i did but I understood you wrong, You can give an example please.

Quote:
Originally Posted by AngeIII View Post
no.

you should to format inside loop only tables one by one.

%s smallint(1), %s smallint(1), ...
PHP Code:
new szText[2048];
new 
szMotdHeader[] = "CREATE TABLE IF NOT EXISTS expmod(";
new 
iLen=0;
for(new 
i=0;i<9;i++)
   
iLen += formatexszText[iLen], charsmax(szText)-iLen"%s smallint(1)%s"tablenames[i],(i==8)?"":",");
iLen+=formatex(szText[iLen], charsmax(szText)-iLen")");
Queries SQL_PrepareQuery(SqlConnection,"%s",szText); 


and also:

Queries = SQL_PrepareQuery(SqlConnection,"%s",szText);
Queries = SQL_PrepareQuery(SqlConnection, szText);
i think its will be bugged cuz if i change map this funcc will called and its wil open another column
or reset them.
Mr.Waffle is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-09-2013 , 12:22   Re: SQL column.
Reply With Quote #9

Try this

PHP Code:
new const szColumns[][]= { ... };

new 
szQuery[2048], temp[64];
formatex(szQuerycharsmax(szQuery), "CREATE TABLE IF NOT EXISTS `expmod` (");

new 
iColumns sizeof(szColumns);
for (new 
0iColumns; )
{
    
formatex(tempcharsmax(temp), "`%s` SMALLINT(1)%s"szColumns[i], (++iColumns) ? ", " ")");
    
add(szQuerycharsmax(szQuery), temp);
}

hQuery SQL_PrepareQuery(SqlConnectionszQuery); 
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 01-09-2013 at 12:22.
YamiKaitou is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 01-09-2013 , 12:36   Re: SQL column.
Reply With Quote #10

not working, there is eror in the logs :
in this line :
PHP Code:
formatex(tempcharsmax(temp), "`%s` SMALLINT(1)%s"szColumns[i], (++iColumns) ? ", " ")"); 
Quote:
L 01/09/2013 - 19:269: Start of error session.
L 01/09/2013 - 19:269: Info (map "de_dust2_long") (file "addons/amxmodx/logs/error_20130109.log")
L 01/09/2013 - 19:269: [AMXX] Displaying debug trace (plugin "Prej.amxx")
L 01/09/2013 - 19:269: [AMXX] Run time error 4: index out of bounds
L 01/09/2013 - 19:269: [AMXX] [0] Prej.sma::MySql_Init (line 26
Mr.Waffle is offline
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 13:46.


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