We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I found this to be a bit disappointing (well, actually a lot disappointing). It can’t be used outside of the parser since in several places it makes calls to various modx class functions for timing of queries; which also brings up the question of adding the overhead to the queries.

    The "select" function has a problem:

    	function select($fields="*", $from="", $where="", $orderby="", $limit="") {
    		if(!$from) return false;
    		else {
    			$table = $from;
    			$where = ($where != "") ? "WHERE $where" : "";
    			$orderby = ($orderby != "") ? "ORDER BY $sort $dir" : "";
    			$limit = ($limit != "") ? "LIMIT $limit" : "";
    			return $this->query("SELECT $fields FROM $table $where $sort $limit;");	
    		}
    	}
    


    Where do the $sort and $dir variables in the ORDER BY clause come from? And $sort is used again in the final return statement.

    I would presume it should be:

    	function select($fields="*", $from="", $where="", $orderby="", $limit="") {
    		if(!$from) return false;
    		else {
    			$table = $from;
    			$where = ($where != "") ? "WHERE $where" : "";
    			$orderby = ($orderby != "") ? "ORDER BY $orderby" : "";
    			$limit = ($limit != "") ? "LIMIT $limit" : "";
    			return $this->query("SELECT $fields FROM $table $where $orderby $limit;");	
    		}
    	}
    


    To be honest, I find that breaking up the query to fit into the argument list is more awkward than defining a full query, then having the wrapper functions process the query and return result sets appropriately. Maybe it just takes getting used to. It will really be awkward in complex queries involving joins.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 34162
      • 1 Posts
      Quote from: sottwell at Jul 21, 2005, 12:49 AM

      I found this to be a bit disappointing (well, actually a lot disappointing).? It can’t be used outside of the parser since in several places it makes calls to various modx class functions for timing of queries; which also brings up the question of adding the overhead to the queries.

      *things left out of quote*

      To be honest, I find that breaking up the query to fit into the argument list is more awkward than defining a full query, then having the wrapper functions process the query and return result sets appropriately.? Maybe it just takes getting used to.? It will really be awkward in complex queries involving joins.

      You are right about the sort and dir. I am kind of surprized it didn’t include the editby=1 string. I could be way off base here but it looks like this came from a conversation between jaredc and benevolentdictator whoever they are.

      on your question about the joins though they are just in the where string.

      you might also look at this .... http://www.actionscript.org/forums/showthread.php3?t=25489 this was written in 2003 but it is interesting.

        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I’m rather fond of ezsql; been using it for years now. http://php.justinvincent.com/

        I suppose it can largely be a matter of what one is accustomed to. But I do need a library/class that I can use independently in complex web-app snippets.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 32963
          • 1,732 Posts
          Quote from: Strider at Jul 21, 2005, 02:25 AM


          You are right about the sort and dir. I am kind of surprized it didn’t include the editby=1 string. I could be way off base here but it looks like this came from a conversation between jaredc and benevolentdictator whoever they are.



          Change noted.

          This library is more a combination of Ralph’s DB functions and a few other db functions from MODx.

          Susan,

          The library was built to work inside MODx. If you want to use it independently then you have the power to modify it to do so. This brings me to the question of whether or not we should be building MODx specific libraries or general purpose libraries?

          On the question on using the select function. The library does not limit you to such functions at all. You are free to use the query() function to perform all your database queries.

          On the issue of using timinng functions. Etomite/MODx has being using these functions long before the DBAPI library. The timining functions are there to allow a developer to note the time it takes to run a query.

          IMO the DBAPI function hopefully will make it easier when moving to other database engines. The select function for example aid the developer in writing SQL statements that are not tied to any specific engine.

          Consider this:

          MySQL: SELECT * FROM table1 LIMIT 10

          MSSQL: SELECT TOP 10 * FROM table1

          DBAPI: select("*","table1","","",10)

          By loading the appropriate DBAPI library file (MySQL or MSSQL) the select function can generate the correct SQL syntax for that database.

          Question:
          Is it that the DBAPI is too difficult to use or should we replace it with a more general purpose library? If so which library would like to see added to the system?
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 4673
            • 577 Posts
            Back to the same questions that we brought up last month.

            I do believe that if an outside API were to be used:
            ezSQL, ADOdb and ADOdb lite were popular topics.

            I seemed to like the ezSQL better than ADOdb lite (ADOdb lite is still in the development stage).
            ADOdb is just soooo huge that it’s a little scary.

            But I thought the in-house modx was supposed to be easier to use?

            I’m no where a pro nor even a novice on this stuff. I just want to use what ever is the easiest and has just the right amount of functions (thereby my interest in ezSQL).

            As for the API -- I’m thinking of when zencart starting talking to some other developers and a unified class API was in the talks to make it easy for different projects to talk to the main cart program. IF this were a reality modx would have a huge jump on most other systems. Just imagine different independent projects going in their own directions but are willing to allow the base system of each a way to talk to each other.

            we do what we do best and they do what they do best.

            ie, phpadsnew -- why build a banner program when they already have a pretty decent system.

            Many would benefit by this. AND we would truly be leaving our mark on the net wink
              Tangent-Warrior smiley
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              What I like about ezsql is that its functions return just the data you are looking for, be it an array of results or a single value.

              As far as the function call syntax, it’s just that I have to write out the whole query to get its logic straight in my head (more or less, anyway), and then having to copy/paste the various parts of it into the function argument list is awkward. I imagine that in time I would be able to "grok" the logic in that form as well.

              And for the timing loops, well, I worked with assembly language a lot in the early x86 days, and still have a yen for fast, tight code. I’m studying how to use the database engine instead of PHP for a lot of the data manipulation that goes on; it’s much more efficient at it.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 32963
                • 1,732 Posts
                Quote from: sottwell at Jul 22, 2005, 12:06 AM

                What I like about ezsql is that its functions return just the data you are looking for, be it an array of results or a single value.?

                One of the things about ezSQL (and some of the APIs we use) is that it must first populate an array with all the values from the recordset. When you get that array returned you would then have to loop throught it’s values again to work with the data.

                IMO that’s 2 sets of loops which results in more processing on the server-side. Agree?

                Here how you can get a recordset and iterate that recordset in one go:

                $ds = $modx->db->select('*','table');
                while($row=$modx->db->getRow($ds)) {
                 // do some stuff here
                }


                What do you think about this method? Is this not faster than ezSQL? Please do a feature comparison, a speed comparison and a usage comparison and let us know where the DBAPI stands

                Carsten,

                As it relates to offering support for third party products we can create a separate API to allow such products to interact with the MODx resources and framework. Something like a MODx SDK
                  xWisdom
                  www.xwisdomhtml.com
                  The fear of the Lord is the beginning of wisdom:
                  MODx Co-Founder - Create and do more with less.
                  • 4673
                  • 577 Posts
                  ahhh, now a SDK would definitely be interesting smiley

                  Cool
                    Tangent-Warrior smiley
                    • 32963
                    • 1,732 Posts
                    Quote from: Carsten at Jul 22, 2005, 03:02 AM

                    ahhh, now a SDK would definitely be interesting smiley

                    Cool

                    Cool,

                    Do you any ideas as to what you might like to see insid ethe SDK? Please if you can all trip in and add ideas, functions or help with creating an SDK or an API for MODx then that would be great. It would also make it also possible for TP4
                      xWisdom
                      www.xwisdomhtml.com
                      The fear of the Lord is the beginning of wisdom:
                      MODx Co-Founder - Create and do more with less.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Quote from: xwisdom at Jul 22, 2005, 09:57 AM

                      Quote from: Carsten at Jul 22, 2005, 03:02 AM

                      ahhh, now a SDK would definitely be interesting smiley

                      Cool

                      Cool,

                      Do you any ideas as to what you might like to see insid ethe SDK? Please if you can all trip in and add ideas, functions or help with creating an SDK or an API for MODx then that would be great. It would also make it also possible for TP4

                      The SDK should have security hooks for SSO (single sign-on) and other user management related hooks at least...those are the biggest areas in application integration. One other quick thought, how about a way to add additional features to the SDK, so if I write a custom module, it could have hooks into the SDK and it becomes available as part of the SDK.