[help+]Does Construct access SQL Databases?

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi,

    I'm going to need lots more details to troubleshoot this. The bind-network option simply sets which interface your server will listen on (for example if your system had two NICs). So I think the problem is something else. Are you behind a router? Do you have port forwarding enabled? Can he telnet to your server and pull a banner?

    You would run WIreshark and have him connect and see if you even see him connecting to your server.

    My guess is you are behind a router and he can't connect to your server, but maybe it is a firewall or config issue. Need more detailed error messages as well.

    Thanks!

  • Hey scidave, thanks for replying

    So, yes, I'm behind a router and have portforwarded the essencial ports already, what ports exacly should I forward? So I can check if there is something left..

    About the other stuffs he unfortunaly is sleeping right now so I will be able only to inform about this other questions tomorrow =(

    but the error was when he tryed to open the program, appeared a script error saying ''host 'his globalip' was unable to conect to this database" I'll send a pic of it tomorrow with more detailed informations..

    But I think it's nothing related to ports cuz times ago I had some private game servers with sql database running here for friends and they always connected..

    Maybe is something about the GRANT privileges? I've readed something about it but not sure if could be it, it seems to allow accounts privileges, but they are connecting with the root username, should then I make a new account with some privileges just for remote access?

  • Maybe is something about the GRANT privileges? I've readed something about it but not sure if could be it, it seems to allow accounts privileges, but they are connecting with the root username, should then I make a new account with some privileges just for remote access?

    I think this is probably your problem since you have the ports forwarded.

    You want to limit what users can do so they don't dork up your database.

    For example you could do the below to allow the user "bar" to do anything on database "foo"

    GRANT ALL ON foo.* TO barhtu@?%? IDENTIFIED BY ?PASSWORD?;

    Ideally, you would create a separate account, as you mentioned, that has less privileges than your root account.

    http://dev.mysql.com/doc/refman/5.1/en/ ... users.html

  • Hey scidave thanks as always for your replies

    So.. just before I made that last post I discovered that was the GRANT thing.. I made another acc just for clients to access remotely and with few privileges.. today I tested it with my friend and it all worked! ;D

    the problem was that the acc I used to them access was the root one and this acc can only be used localy, from my PC only.. so I made a new one that could be accessed anywhere by adding a % at host

  • Hey Scidave.. do u have any idea to how make only be possible to use Letters and numbers in a editbox checking with a python script?

    tryed using strspn(Editbox.Text, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890")

    not even sure if 'strspn' exists in python..

    I need to discover the exact string method.. so I could try:

    if editbox.text contains only letters and/or numbers it would be okay.

    then if the editbox.text have a symbol letter like '%' or '&' it will inform you that it's incorrect.

    EDIT: I did ;D

    used the strip function to compare with the result

  • Awesome! Glad to hear things are working good. This is indeed a great thread to learn database access.

  • Hey scidave, I'm trying to get simple results from the database, right now I'm executing a query and after that I use fetchone() function to get the result, but the result instead to be just a simple string like in the database, have some more digits.. I'll try to explain better with an example:

    In a database called 'TEST' there is a username called TESTER

    so I execute a query to get this username and put in a Text object in construct.

    the result instead to be just "TESTER" is "('TESTER,')" so after the results I need to remove those other things with a strip function.

    Now if I get a result from a value in the database, instead to be just the value(4 for example), it comes with "(4L)"..

    so this is my question, is there any way I could just get the exact result from a database without those brackets, etc?

  • The results are usually returned as a Tuple or if nothing is available the result will be None. So you should access the result as a Python list.

    For example:

    cursor.execute ("SELECT name, category FROM animal")
       while (1):
         row = cursor.fetchone ()
         if row == None:
           break
         print "%s, %s" % (row[0], row[1])
       print "Number of rows returned: %d" % cursor.rowcount
    [/code:3q411di1]
    
    You could also retrieve the rows as Python dictionaries to retrieve results by name (and not index):
    
    [code:3q411di1]
    cursor.close ()
       cursor = conn.cursor (MySQLdb.cursors.DictCursor)
       cursor.execute ("SELECT name, category FROM animal")
       result_set = cursor.fetchall ()
       for row in result_set:
         print "%s, %s" % (row["name"], row["category"])
       print "Number of rows returned: %d" % cursor.rowcount
    [/code:3q411di1]
    
    Hopefully, that was the problem!
  • This while(1) from the first code means what?

    it's true?

    I'll try it with Construct and see if was what I was looking for..

    instead of print I should use SetText right?

    Also, what is the difference retrieve as python dictionaries? didn't understood what u meant by index..

  • This while(1) from the first code means what?

    it's true?

    It means loop forever.

    instead of print I should use SetText right?

    Correct. I was just showing an example you could test in straight Python.

    Also, what is the difference retrieve as python dictionaries? didn't understood what u meant by index..

    If the result is return as a Tuple (a List) and you just print out the Tuple you will get a funky looking "('TESTER,')" <----a Tuple with only one entry. Instead if you said row[0], that would just return "TESTER" as it is the first element/index in the row.

    All of this is just a guess as I actually haven't tried this out in code..don't have my computer with the database on it with me right now...I might be wrong on some of this.

  • Hey Scidave, I think it worked, here is the code:

    user=username.Text
    
    query4="""SELECT STATUS FROM ACCOUNTS WHERE USERNAME = %s"""
    cursor.execute(query4,(user))
    
    results=cursor.fetchall()
    for row in results:
     value = row[0]
    
     Text12.SetText(str(value))
    [/code:3ukj37gj]
    
    but it doesn't work with fetchone(), only fetchall..probably because of 'for'.. don't know.. Could I get the same result using fetchone() ?
  • You can use fetchone() to get the rows one at a time, or fetchall() to get them all at once.

    So it is just a difference in syntax. If you had a massive databse then to save on memory you might want to use fetchone(), but in your case it doesn't practically matter which one you use.

  • Hey ;D

    this time it's more about a curiosity than a question..

    how do I make many Insertions on the database at the same time?

    Right now the method I'm using is this:

    sql1="INSERT"
    cursor.execute(sql1)
    sql2="INSERT"
    cursor.execute(sql2)
    sql...="INSERT"
    cursor.execute(sql...)[/code:1d3cl0fd]
    
    Can I insert everything I want at the sime time, without the need to use execute many times in one code?
  • sqlite with Python has an executescript() function. The best the mysqldb has is a executemany() function (simple example below):

    cursor.executemany(

    """INSERT INTO breakfast (name, spam, eggs, sausage, price)

    VALUES (%s, %s, %s, %s, %s)""",

    [ ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ), ("Not So Much Spam Plate", 3, 2, 0, 3.95 ), ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 ) ] )

    This link may be useful as well for showing more complexity:

    http://stackoverflow.com/questions/9747 ... xecutemany

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's really great and now that u said about executemany I remember I already readed about it.. but at least now I know how to use ;D

    so.. as always, thanks Scidave!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)