Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75852


Change subject: Some refactoring in ExtendedMySQLAbstraction
......................................................................

Some refactoring in ExtendedMySQLAbstraction

Change-Id: I04abb519f2a51888af74a352ea1c8476e3a68b23
---
M src/MWDB/ExtendedMySQLAbstraction.php
1 file changed, 29 insertions(+), 5 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase 
refs/changes/52/75852/1

diff --git a/src/MWDB/ExtendedMySQLAbstraction.php 
b/src/MWDB/ExtendedMySQLAbstraction.php
index 80e9e36..a9040e2 100644
--- a/src/MWDB/ExtendedMySQLAbstraction.php
+++ b/src/MWDB/ExtendedMySQLAbstraction.php
@@ -73,15 +73,28 @@
        protected function getFieldSQL( FieldDefinition $field ) {
                $sql = $this->getFieldType( $field->getType() );
 
-               if ( $field->getDefault() !== null ) {
-                       $sql .= ' DEFAULT ' . $this->getDB()->addQuotes( 
$field->getDefault() );
-               }
+               $sql .= ' ' . $this->getDefault( $field->getDefault() );
+
+               $sql .= ' ' . $this->getNull( $field->allowsNull() );
+
+               if($field->getIndex()==FieldDefinition::INDEX_PRIMARY && 
$field->getName()!=='id') {q($field);}
+               $sql .= ' ' . $this->getIndexString( $field->getIndex() );
 
                // TODO: add all field stuff relevant here
 
-               $sql .= $field->allowsNull() ? ' NULL' : ' NOT NULL';
-
                return $sql;
+       }
+
+       protected function getDefault( $default ) {
+               if ( $default !== null ) {
+                       return 'DEFAULT ' . $this->getDB()->addQuotes( $default 
);
+               }
+
+               return '';
+       }
+
+       protected function getNull( $allowsNull ) {
+               return $allowsNull ? 'NULL' : 'NOT NULL';
        }
 
        /**
@@ -107,4 +120,15 @@
                }
        }
 
+       protected function getIndexString( $indexType ) {
+               switch ( $indexType ) {
+                       case FieldDefinition::INDEX_PRIMARY:
+                               return 'PRIMARY KEY AUTO_INCREMENT';
+               }
+
+               // TODO: handle other index types
+
+               return '';
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/75852
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04abb519f2a51888af74a352ea1c8476e3a68b23
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to