[LIB] SQLibrary - Database wrappers for all database engines

Discussion in 'Resources' started by PatPeter, Aug 27, 2011.

  1. Offline

    okami35

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I understand, but now I open a connection here:

    Code:
    Connection connexion;
    
    connexion = sqlite.open();
    And after, I use the SAME connection object for my statement:

    Code:
    PreparedStatement prepare = connexion.prepareStatement("INSERT INTO test(nom, age) VALUES(?, ?)");
    So, there is only one object connection... And always the same error

    Thank you very much for your help
  2. Offline

    HSAR

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Without meaning any disrespect, it would be much appreciated if you conducted this via PMs since I'd like my notifications on this thread to be about the library itself...

    This post has been edited 1 time. It was last edited by HSAR Oct 13, 2011.
  3. Offline

    okami35

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    yes I understand, but i think i am not the only one to have problems with this API. And I thought I was allowed to ask help on this thread.

    Sorry
  4. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @blackhatrob: Will do.

    Yes please, feel free to write any methods and send them to me. I'll work on getting the code on GitHub for commenting, etc. etc.

    @ Everyone else: Do I have to read all those posts to discover something I fixed in the code, or was it an implementation issue?

    Also, if I do get this code on GitHub I'll be uploading the test plugin with example code for MySQL and SQLite. Can I add any of these previous posts to it?

    The thread's purpose is to provide help as well as work on developing the library. Now I haven't read the posts yet, but if it has any good relation to the plugin he should have asked here.

    Naw, feel free to any time. If it's a very specific issue related to SQL and not the library itself, then resort to another thread or PMs.

    This post has been edited 1 time. It was last edited by PatPeter Oct 14, 2011.
  5. Offline

    okami35

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thank you for your answer, but i think my error comes from the library, you don't have methods for INSERT. The method "query" must return a resultset...
    A new example with the latest version would by very apreciated.
  6. Offline

    thommy101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hi,
    Is it possible to get a list of the results returning from the database?
    Something like this returning a list with the results
    PHP:
    SELECT FROM database WHERE world " + world + ";

    The coordinates are stored seperatly in the database: X, Y and Z all have a seperate column.
    Is this possible to get?

    This post has been edited 1 time. It was last edited by thommy101 Oct 16, 2011.
  7. Offline

    herghost

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can someone provide a example of there connection code for the MySQL?

    Thanks
  8. Offline

    Aleksander

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Does this library support num rows like mysql_num_rows()? I really need this function.

    EDIT: I might have created a way to, try this snippet for the guys that need it.
    Code:
    	public int numRows(ResultSet query)
    	{
    		try
    		{
    			if(sqlite.checkConnection())
    			{
    				query.last();
    				int rowCount = query.getRow();
    				return rowCount;
    			}
    		}
    		catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		return 0;
    	}
    
    EDIT2: No, that doesn't work, hoping for a better response.

    This post has been edited 3 times. It was last edited by Aleksander Oct 17, 2011.
  9. Offline

    untergrundbiber

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I have a porblem with SQLite an UPDATE-Query

    Code:

    Code:
    
    String query5 = "UPDATE unlock SET unlock = 1 ,unlockname = '" + player.getName().toLowerCase() + "' ,unlocktime = '" + plugin.getDateTime() + "' WHERE unlock.id = " + id + ";";
    
    bcguestunlock.sqlite.query(query5);
    
    
    Github

    When i throw the query the server hang with this message:

    [SQLite] Error at SQL Query: query does not return ResultSet

    Same error with other queries without ResultSet like DELETE

    With the old lib from alta189 and updateQuery it works perfectly

    Anyone can help?

    This post has been edited 2 times. It was last edited by untergrundbiber Oct 19, 2011.
  10. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I've been trying to create a universal method for query() for a while, are you sure it's the most recent version of the library? I tried a trick to stop it from doing this.

    http://forums.bukkit.org/threads/lib-tut-mysql-sqlite-bukkit-drivers.33849/#post-641927

    This is on my list of things to do but I have nowhere near enough time for it right now.

    As I said above, I've been trying to create a universal query() method just as I made an interface for all databases. I'll try to look into it this weekend and may have to abandon that goal.
  11. Offline

    herghost

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Download link is dead?
  12. Online

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Noos! The Attachement cannot be shown at this time..
    It's not working :O (The download, I mean)
  13. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Download links are working for me.
  14. Online

    Lolmewn BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    seems to work again, yes.
  15. Offline

    Nick Ippoliti

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can anyone point me in the direction for documentation for this?
  16. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Right now it's only in the Javadoc and the examples in the previous pages (look at the bottom of page 1).

    I'll be working on this a lot more come mid-December.
  17. Offline

    Nick Ippoliti

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    EDIT: Nevermind, just a forgotten Parentheses...

    This post has been edited 1 time. It was last edited by Nick Ippoliti Nov 30, 2011.
  18. Offline

    digga

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @ Aleksander

    Code:
    public int countRows(ResultSet rs) {
                int rowCount = 0;
                try {
                    if (rs == null) return 0;
                    rs.next();
                    rowCount = rs.getInt(1);
                    rs.close();
                } catch (SQLException ex) {
                    Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
                }
                return rowCount;
            }
    I use this funtion;)
  19. Offline

    Nick Ippoliti

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Bug to report. Seems that if a query fails, the server crashes without warning. For example:
    This is the table:
    Code:
    [id INTEGER PRIMARY KEY] [TestText text]
    1                        'test'
    2                        'Bob'
    and if I used
    Code:
    dbManager.query("SELECT TestText as testvar where TestText = 'Bob'")
    ** assuming dbManager is an SQLite object.
    there would be no error and no random crash. However, if I used:
    Code:
    dbManager.query("SELECT TestText as testvar where TestText = 'Joseph'")
    the server crashes without logging or any warning. Maybe it's just my newness to SQL, but I've checked my query and it runs perfectly unless there is no value returned ( value does not exist in table), and then the server crashes. Can anyone confirm?
  20. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @Nick Ippoliti I'll look into it when I have free time Nick. Generally I work on this at the same time as my plugin, so if I don't have any time to work on that you know I have no time to work on this.
  21. Offline

    Nick Ippoliti

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks. If you thought I sounded demanding, I wasn't trying to be, just giving you a heads up on an issue.
  22. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Just a policy we have here, make sure your files have a non-attachment download link.
  23. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Naw, I love when people give me a heads up.

    Really? I never knew, thanks Swear. I'll get the next version up on MediaFire and remove the older version at the next opportunity. Are the guidelines posted anywhere?
  24. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You can use MediaFire if you want, but I'd rather you use something that allows direct linking. I don't know why this isn't on github, it automatically will package the source into a zip. Perfect for this.
  25. Offline

    Celtic Minstrel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Is the policy because you have to be registered to download attachments? Because if so, I wholeheartedly approve.
  26. Offline

    DomovoiButler

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  27. Offline

    Ghost1227

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Following your 'How to Install' section, I am getting a 'The import lib.PatPeter cannot be resolved' error.
  28. Offline

    DomovoiButler

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    not being mean here, but you can make your own library
    if you only want to use sqlite you dont have to have sql library
    study this http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
  29. Offline

    PatPeter

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Create a folder called 'lib' in the root folder of your plugin/src directory (for Eclipse), followed by a folder called 'PatPeter' inside of the 'lib' folder.

    Domo, the point of this library is to make a shortcut to that method. Please refrain deflecting users away from this library.
  30. Offline

    Nick Ippoliti

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Seems that the server crash is fixed. May have been bukkit updates, or it may have been the try{ statement I added to the SQLite.java. The change is on my plugin's Github page. The change is on line 132. EDIT: seems I have multiple lib folders. The one I am referring to is the one under ~/src/lib/PatPeter/SQLibrary/SQLite.java

    This post has been edited 1 time. It was last edited by Nick Ippoliti Dec 21, 2011.

Share This Page