[LIB] SQLibrary - Database wrappers for all database engines

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

Thread Status:
Not open for further replies.
  1. Offline

    dark navi

    I fixed that specific instance of grabbing the integer value, but I think I found out that it was because I was calling a query before the 'finally' that closed my ResultSet was called.

    So I just altered the SQLite class's query method to add a finally / RS.close():
    Code:
    @Override
    public ResultSet query(String query) {
    Statement statement = null;
    ResultSet result = null;
     
    try {
    connection = this.open();
    statement = connection.createStatement();
    result = statement.executeQuery("SELECT date('now')");
     
    switch (this.getStatement(query)) {
    case SELECT:
    result = statement.executeQuery(query);
    break;
     
      case INSERT:
      case UPDATE:
      case DELETE:
      case CREATE:
      case ALTER:
      case DROP:
      case TRUNCATE:
      case RENAME:
      case DO:
      case REPLACE:
      case LOAD:
      case HANDLER:
      case CALL:
      this.lastUpdate = statement.executeUpdate(query);
      break;
     
    default:
    result = statement.executeQuery(query);
     
    }
    return result;
    } catch (SQLException e) {
    if (e.getMessage().toLowerCase().contains("locking") || e.getMessage().toLowerCase().contains("locked")) {
    return retry(query);
    } else {
    this.writeError("SQL exception in query(): " + e.getMessage(), false);
    }
     
    }
    finally
    {
    if(result != null)
    try {
    result.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    return null;
    }
    Is this sloppy / wrong? It seems to work for me, although I can't really try to produce what I was getting wrong.

    EDIT: Never mind, that was a bad idea. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  2. Offline

    bajsko

    Nice, will be using it
     
  3. Offline

    bloodsplat

    I cant seem to find a tutorial to use this library if someone could point me towards one that would be greatly appreaciated. I'm just after creating a SQLite db and adding/reading values from it
    Thankyou
     
  4. Offline

    Neodork

    Please read this post.
     
  5. Offline

    bloodsplat

    Appreciated thanks Neodork
     
  6. Offline

    messageofdeath

  7. Offline

    Pew446

    Every time I reload my server or restart my server the database is locked.. I'm using SQLite, not MySQL. I make sure to close all my ResultSets, but nothing works. Please help :c

    Well if anyone was curious, I fixed it. I was running the dev build, and after switching to the stable build I quit getting warnings to close my ResultSets, and started getting warnings about how my queries didn't return ResultSets. It's a very simple fix, in SQLite.java:

    Code:
    @Override
        public ResultSet query(String query) {
            ...
                switch (this.getStatement(query)) {
                    case SELECT:
                        result = statement.executeQuery(query);
                        return result;
                       
                    default:
                        statement.execute(query); //Right here <-- change it to execute from executeQuery
                        return result;   
                }
           ...
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  8. Offline

    PatPeter

    Thanks for the fix! I believe I had fixed this in previous builds but have not submitted it yet.
     
  9. Offline

    Pew446

    No problem. Thanks for keeping this updated. SQLite is the best thing that has happened in a long time.
     
    dark navi likes this.
  10. Offline

    PatPeter

    4.0 is coming out soon for anyone who still uses this library. Most major change is that the library will now be distributed as a plugin so that you will have to add it as an External Jar (if you use Eclipse). This is to cut down on the number of dead-end forks made that just sit in cyberspace.
     
  11. Offline

    dark navi

    But doesn't that mean that anyone using this also has to include your .jar with their plugin? I find that to be a bit tedious. I love your library by the way.
     
  12. Offline

    PatPeter

    Including a Jar and adding it to plugin.yml/the server is a LOT easier than the current method. The current method requires 8 steps. Using a Jar only takes 3.
    1. Add the Jar to External Jars/plugin.yml.
    2. Install the Jar onto the server.
    3. Add the import statement.
     
  13. Offline

    Giant

    4. Require any server running a plugin using the library to also run the library jar.
     
    dark navi likes this.
  14. Offline

    dark navi

    That's what I was referring to. Adding this to my current project is just as easy... copy the class files over.
     
  15. Offline

    Giant

    Well, if it gets enforced, I suppose you could always start using my drivers :D (Not advertising at all or anything...)
     
    Pew446 and dark navi like this.
  16. Offline

    Pew446

    Ehh I don't want to make my players require downloading another jar.. I chose SQLite because it was simple to setup... they didn't have to do anything. I'm not updating.
     
    dark navi likes this.
  17. Offline

    PatPeter

    By your players you mean the people who download your plugin? How is extracting a folder of java source files into a folder that you then you have symlink in Eclipse to your library's location any simpler than just dragging and dropping an extra jar into your server's plugins directory?

    You should still be able to download all the files from the GitHub anyway, if you don't want to use the plugin.
     
  18. Offline

    dark navi

    I just honestly think that no one will use the .jar file for any production plugin.
     
    Pew446 likes this.
  19. Offline

    Coelho

    You could make your plugin automatically download the lib.
    Do you even realize how many plugins have dependencies, and why dependencies were made in Bukkit?
     
  20. Offline

    dark navi

    I have never had a plugin have a database dependency.
     
  21. Offline

    Coelho

    I never said database dependency. I said dependency in general, the essence of a required external plugin.
     
  22. Offline

    dark navi

    Oh of course there are dependencies. Vault is a great example of where a bridge / dependency would be appropriate. I was specifically commenting on the usage of this plugin as one, but I suppose I cannot speak for the entire development community.
     
  23. Offline

    Pew446

    Bah, you can speak for me, I don't care how hard it is to include the library into my plugin, what I care about is how easy it is for the player to set up my plugin. It's more simple to download one jar from the big download button on the dev bukkit page than put giant letters everywhere warning the plugin wont work unless you download another plugin, which still people manage to miss. I care about how simple it is for my plugin users, not how simple it is for me.
     
  24. Offline

    PatPeter

    Based on the input, I'll leave support for the previous method, i.e. adding the source files directly into the jar, alongside the .jar.

    Next version will be out once I finish some experimental classes with it. Several method such as open(), close(), and query() now throw SQLException so that it doesn't simply write and error to console only for the next call to result in a NullPointerException. Use of writeInfo() and writeError() date back to the first version of the plugin and they may or may not be phased out.
     
    dark navi and Pew446 like this.
  25. Offline

    dark navi

    Good guy developer: listens to community.
     
  26. Offline

    Pew446

    :D!
     
  27. Offline

    rails

    The stable build download 404's
     
  28. Offline

    PatPeter

    SQLibrary 3.1 has been released! All information has been moved to dev.bukkit.org:

    http://dev.bukkit.org/server-mods/sqlibrary/

    This is actually the first release, all the rest have been alphas and betas. We are waiting on the jar to be approved, but I've already pushed the files to GitHub.

    I had literally just brought it down so that you can download the latest version. That version was massively out-of-date (3.0.6, missing 3.0.7, 3.0.8, and 3.1).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  29. Offline

    Lolmewn

    Very nice indeed! *implements*
     
  30. Offline

    rails

    Heh, heh, thanks.
     
Thread Status:
Not open for further replies.

Share This Page