Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    Switzerland
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh How to use sqliteCreateAggregate inside class

    This works fine:
    PHP Code:
    function GroupConcatStep(&$context$string$separator ',') {
      
    $context .= $separator $string;
    }
    function 
    GroupConcatFinalize(&$context) {
      return 
    $context;
    }

    $Db = new PDO('sqlite: MyDb.sqlite');
    $Db->sqliteCreateAggregate('GROUP_CONCAT''GroupConcatStep''GroupConcatFinalize'2); 
    But I don't know how to do the same from inside a class. I don't get the names of the callback functions (methods) right. So the code below does not work:

    PHP Code:
    class MyClass {
      public function 
    Connect() { 
        
    $this->Db = new PDO('sqlite:'.$Path.'/'.$this->DbName);
        
    $this->Db->sqliteCreateAggregate('GROUP_CONCAT''MyClass::GroupConcatStep''MyClass::GroupConcatFinalize'2);
      }
      public function 
    GroupConcatStep(&$context$string$separator ',') {
        
    $context .= $separator $string;
      }
      public function 
    GroupConcatFinalize(&$context) {
        return 
    $context;
      }

    visit my website at www.speich.net

  • #2
    New Coder
    Join Date
    Jul 2005
    Location
    Switzerland
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Never mind, I just found out. This does the trick:

    PHP Code:
    $this->Db->sqliteCreateAggregate('GROUP_CONCAT', array($this'GroupConcatStep'), array($this'GroupConcatFinalize')); 
    visit my website at www.speich.net

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That is correct, I'm glad you found the solution!
    Just remember that callbacks always take class/object and parameters as array arguments and you'll be fine. The callBack definition is kind of difficult to find in PHP (hidden under pseudo types >.< http://ca3.php.net/manual/en/languag...types.callback), and their namespace usage has also been terribly documented (which I'm not worried about, there is still time). I have no idea why they decided to do it this way; I figure a function pointer definition or delegate would have been a far better solution since we would be able to typecast our own callback definitions.
    Methinks we're stuck with this way now though >.<
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •