Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
  • Tag's "Next" not working properly

    Thanks for the answer :)

    I already tried removing the "megaphone" URL and still happening :(

  • Can I add discussion using code?

    I just want to inject a discussion right into the forum, just like they started it.

  • Whats Vanilla Coloured and goes Bonk ?

    Ongoing problems with Rackspace have escalated, and one of our critical servers is down. We're investigating.

    Well that's their last tweet.

  • Whats Vanilla Coloured and goes Bonk ?

    What's occuring fellas ?

    Every time I come on I get Bonk, or server error. Have you migrated servers ?

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    @x00: Thanks, prompt reply as usual. Unfortunately, specifying the index name alone would not be enough, as the order of the columns matters, as well as the ordering of the data itself (ASC, DESC). Indexes are much more complex than it seems, and all this "tuning" is needed more often than most people think.

    I agree with the fact that covering everything via code is not easy, that's one of the reasons why I tend to avoid ORM libraries (they have their place, but there are things than handwritten SQL can do much better).

    Back to the issue, I'll attempt to extend Gdn_DatabaseStructure with an Index() method, so that it will still be possible to use current Table definition mechanism for simpler indexes, and create complex ones separately (which is what I do via SQL anyway, it's easier to read and maintain).

    Thanks to all for the replies/comments/contributions.

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    x00 said: I gave up on coding idealism years ago.

    LOL!

    Oh, I love this one too. Time for another line on a t-shirt. Or another line in a signature.

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    you could create a wrapper round this class create your own more complete _IndexSql

    as UnderDog said this is just a wrapper. I seen full blown ORM libraries that still doesn't do everything. I gave up on coding idealism years ago.

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    Another possible hack

    Gdn::Structure()
           ->Table('MyTable')
           ->PrimaryKey('MyTableID') 
           ->Column('SomeUniqueField', 'int', FALSE, 'unique')
           ->Column('FirstName', 'varchar(100)', FALSE, '/*myindex*/') 
           ->Column('LastName', 'varchar(100)', FALSE, '/*myindex*/')
           ->Set();
  • Issue when creating multi-column Indexes using Vanilla's Database Class

    Looking at the code

    ....
       protected function _IndexSql($Columns, $KeyType = FALSE) {
          $Result = array();
          $Keys = array();
          $Prefixes = array('key' => 'FK_', 'index' => 'IX_', 'unique' => 'UX_', 'fulltext' => 'TX_');
          
          // Gather the names of the columns.
          foreach ($Columns as $ColumnName => $Column) {
             $ColumnKeyTypes = (array)$Column->KeyType;
    
             foreach ($ColumnKeyTypes as $ColumnKeyType) {
                if(!$ColumnKeyType || ($KeyType && $KeyType != $ColumnKeyType))
                   continue;
    
                // Don't add a fulltext if we don't support.
                if ($ColumnKeyType == 'fulltext' && !$this->_SupportsFulltext())
                   continue;
    
                if($ColumnKeyType == 'key' || $ColumnKeyType == 'index') {
                   $Name = $Prefixes[$ColumnKeyType].$this->_TableName.'_'.$ColumnName;
                   $Result[$Name] = $ColumnKeyType." $Name (`$ColumnName`)";
                } else {
                   // This is a multi-column key type so just collect the column name.
                   $Keys[$ColumnKeyType][] = $ColumnName;
                }
             }
          }
    
          
          // Make the multi-column keys into sql statements.
          foreach($Keys as $KeyType2 => $Columns) {
             if($KeyType2 == 'primary') {
                $Result['PRIMARY'] = 'primary key (`'.implode('`, `', $Columns).'`)';
             } else {
                $Name = $Prefixes[$KeyType2].$this->_TableName;
                $Result[$Name] = "$KeyType2 index $Name (`".implode('`, `', $Columns).'`)';
             }
          }
          
          return $Result;
       }
    

    It is 90% there you just need a way of specify the index name

    I wonder if this will work:

    Gdn::Structure()
           ->Table('MyTable')
           ->PrimaryKey('MyTableID') 
           ->Column('SomeUniqueField', 'int', FALSE, 'unique')
           ->Column('FirstName', 'varchar(100)', FALSE, ' ') 
           ->Column('LastName', 'varchar(100)', FALSE, ' ')
           ->Set();

    or

    Gdn::Structure()
           ->Table('MyTable')
           ->PrimaryKey('MyTableID') 
           ->Column('SomeUniqueField', 'int', FALSE, 'unique')
           ->Column('FirstName', 'varchar(100)', FALSE, ' unique') 
           ->Column('LastName', 'varchar(100)', FALSE, ' unique')
           ->Set();
  • Unit Testing a Plugin

    Hi all, I'm developing my third plugin for Vanilla and I was wondering if there's a way to use PHPUnit (or similar) to run Unit Tests on them, as it would save me quite a bit of time.

    Thanks in advance for the replies.

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    Correction: the class I'm referring to is Gdn_DatabaseStructure.

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    Thanks for the information.

    I honestly thought that the DataBase class of Vanilla was a thin wrapper around the PDO class. Might be mistaking though.

  • Report a post option?

    Hi,

    Apologies if this is a stupid question but... I am due to move from VBulletin to Vanilla. In VBulletin there is a fairly prominent "Report" button that will flag a post to the moderators. I am using the VanillaPress theme and have searched plugins but cannot seem to find a "Report" option in Vanilla. Am I missing something obvious?

    Many thanks, Rob

  • Issue when creating multi-column Indexes using Vanilla's Database Class

    I was working with Vanilla's Database Class to create some tables for my plugin, and I noticed two issues in the mechanism that builds DDL statements.

    1- It doesn't allow to create multi-column Indexes. I followed the code that applies schema changes (namely Gdn_MySQLStructure->_Create()) and I noticed there's no way to specify an index name and to include more than columns into it. By declaring a column index, a new index containing only that column will be created on the database.

    Example
    Gdn::Structure() ->Table('MyTable') ->PrimaryKey('MyTableID') ->Column('SomeUniqueField', 'int', FALSE, 'unique') ->Column('FirstName', 'varchar(100)', FALSE, 'index') ->Column('LastName', 'varchar(100)', FALSE, 'index') ->Set();

    The resulting table will have, besides the Primary Key, the following indexes: - Ix_MyTable_SomeUniqueField -> Unique Index
    - Ix_MyTable_FirstName -> Index
    - Ix_MyTable_LastName -> Index

    There's no way to create a single index containing FirstName and LastName.

    2- It forces composite indexes for Unique Keys It may seem a contradiction of point 1, but it's not. It's not possible to explicitly create a multi-column index, but Vanilla creates one single Unique index, no matter how many columns have been indicated as unique.

    Example
    Gdn::Structure() ->Table('MyTable') ->PrimaryKey('MyTableID') ->Column('SomeUniqueField', 'int', FALSE, 'unique') ->Column('FirstName', 'varchar(100)', FALSE, 'unique') ->Column('LastName', 'varchar(100)', FALSE, 'unique') ->Set();

    This time, the resulting table will have one single unique key, containing SomeUniqueField, FirstName and LastName. Again, it's not possible to explicitly create a multi-column index containing only the desired columns.

    The above are serious limitations in the Schema functions, as designing Indexes properly is critical for optimal performances in a database. This is especially true for multi-column indexes, where the position of a column in the Index definition can make a significant difference.

    Currently, as a workaround, I create the affected indexes using a manually written SQL Statement. This implies having to manually deal with schema changes between versions, which is not optimal. I could also try to modify the Core class and submit it to the Community for review, but I'd first have to find how the process to follow.

  • Vanilla shows wrong canonical URL for categories?

    2.1 has a lot of changes and we have a lot of backwards-compatibility with theming right now. If you don't know what you are doing then don't go unstable.

    With regards to the canonical url thing. I may take out that if statement since it can't hurt, but for now don't worry about the canonical url not being there. The purpose of the canonical url is to remove ambiguity between two of the same page on different urls.