strcat and sqlite help
#1

Okay so I am trying to set up these fields in the table "Obj1X","Obj1Y","Obj1Z" and so on all the way to Obj600X can anyone tell me why this isn't working?

PHP код:
    new bstring[256],query[138],final[5000];
    
db_free_result(db_query(houses,"CREATE TABLE IF NOT EXISTS `Houses`(`EnterX`,`EnterY`,`EnterZ`,`EnterVw`,`EnterInt`,`Set`,`Owned`,`Price`,`ExitX`,`ExitY`,`ExitZ`,`ExitVw`,`ExitInt`,`Owner`"));
    
format(bstring,sizeof(bstring),"CREATE TABLE IF NOT EXISTS `Furniture` (`Owner`,",21);
    
strcat(query,bstring,1500);
    for(new 
0<600i++)
    {
        if(
== 0) { 1;}
        if(
>= 1)
        {
            
format(bstring,sizeof(bstring),"`Obj%dX`,`Obj%dY`,`Obj%dZ`,`Obj%dRx`,`Obj%dRy`,`Obj%dRz`,",i,i,i,i,i,i);
            
strcat(query,bstring,1500);
        }
    }
    
format(final,sizeof(final),"%s`Vw`",query);
    
db_query(houses,final);
    
printf("%s",final); 
print outputs this
PHP код:
CREATE TABLE IF NOT EXISTS `Furniture` (`Owner`,`Obj1X`,`Obj1Y`,`Obj1Z`,`Obj1Rx`,`Obj1Ry`,`Obj1Rz`,`Obj2X`,`Obj2Y`,`Obj2Z`,`Obj2Rx`,`Obj2R`Obj599X`,`Obj599Y`,`Obj599Z`,`Obj599Rx`,`Obj599Ry`,`Obj599Rz`,`Obj599X`,`Obj599Y`,`Obj599Z`,`Obj599Rx`,`Obj599Ry`,`Obj599Rz`,`Vw`
Reply
#2

Okay so I tried increasing the string sizes to 5000 just to make sure that not enough cells wasn't the problem but all that did was make the server console stop responding then crash eventually
Reply
#3

You don't see the problem in your query output?

pawn Код:
`Obj2Rx`,`Obj2R`Obj599X`,
Missing a comma there between obj2r and obj559x.

You could vastly reduce the amount of columns in your table by putting all data from a single object into a column. So that a single column holds the objects - "objectid x, y, z, rx. ry. rz" and anything else you might need. Then split the data when you retrieve it. This also makes your code much more manageable.

This way you can have many many more objects per house without having to do HUGE queries.

SQLite can handle a lot of columns per table, but it's not good practice to do so.
Reply
#4

Quote:
Originally Posted by iggy1
Посмотреть сообщение
You don't see the problem in your query output?

pawn Код:
`Obj2Rx`,`Obj2R`Obj599X`,
Missing a comma there between obj2r and obj559x.

You could vastly reduce the amount of columns in your table by putting all data from a single object into a column. So that a single column holds the objects - "objectid x, y, z, rx. ry. rz" and anything else you might need. Then split the data when you retrieve it. This also makes your code much more manageable.

This way you can have many many more objects per house without having to do HUGE queries.

SQLite can handle a lot of columns per table, but it's not good practice to do so.
Yes I saw the problem but did you look at my formatting string? I dont see why the comma isn't going there and why its skipping from obj2 to obj599.

And I didnt' think about doing that, that is actually a great idea. Gonna work on doing that now.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
None of you understand the point of a relational database! Don't put all the objects for a house in that houses row at all! Make a separate table for objects - one per row, with a foreign key pointing back to the house that owns them.
So wait you are saying each object should get its own row, rather then each set of objects? That does make more sense then a huge ass query thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)