]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
tried to clean strdup() mess: we now have wxStrdup[AW] which should be always available
[wxWidgets.git] / src / common / dbtable.cpp
index 03d947568a02750862c11b3ae5e54e3927571228..384310ce8c49da69c8b04fc7c3073671d7921a2b 100644 (file)
@@ -1651,6 +1651,26 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
         sqlStmt += pDb->SQLColumnName(pIdxDefs[i].ColName);
 //        sqlStmt += pIdxDefs[i].ColName;
 
+        // MySQL requires a key length on VARCHAR keys
+        if ( pDb->Dbms() == dbmsMY_SQL )
+        {
+            // Find the details on this column
+            int j;
+            for ( j = 0; j < noCols; ++j )
+            {
+                if ( wxStrcmp( pIdxDefs[i].ColName, colDefs[j].ColName ) == 0 )
+                {
+                    break;
+                }
+            }
+            if ( colDefs[j].DbDataType ==  DB_DATA_TYPE_VARCHAR)
+            {
+                wxString s;
+                s.Printf(wxT("(%d)"), colDefs[i].SzDataObj);
+                sqlStmt += s;
+            }
+        }
+        
         // Postgres and SQL Server 7 do not support the ASC/DESC keywords for index columns
         if (!((pDb->Dbms() == dbmsMS_SQL_SERVER) && (strncmp(pDb->dbInf.dbmsVer,"07",2)==0)) &&
             !(pDb->Dbms() == dbmsPOSTGRES))
@@ -2586,8 +2606,8 @@ wxVariant wxDbTable::GetCol(const int colNo) const
 
 void csstrncpyt(char *s, const char *t, int n)
 {
-    while ((*s++ = *t++) && --n)
-    {};
+    while ( (*s++ = *t++) != '\0' && --n )
+        ;
 
     *s = '\0';
 }