Q:

standard unambiguos format [R] MySQL imported data

OK, to set the scene, I have written a function to import multiple tables from MySQL (using RODBC) and run randomForest() on them.  
This function is run on multiple databases (as separate instances). 
In one particular database, and one particular table, the "error in as. POSIXlt.character(x, tz,.....): character string not in a standard unambiguous format" error is thrown.  The function runs on around 150 tables across two databases without any issues except this one table. 
Here is a head() print from the table:
MQLTime bar5 bar4 bar3 bar2 bar1 pat1 baXRC
1 2014-11-05 23:35:00  184   24    8   24   67  147  Flat
2 2014-11-05 23:57:00  203  184  204   67   51  147  Flat
3 2014-11-06 00:40:00  179  309   49  189   75   19  Flat
4 2014-11-06 00:46:00   28  192   60   49  152  147  Flat
5 2014-11-06 01:20:00  309   48    9   11   24   19  Flat
6 2014-11-06 01:31:00   24  177   64  152  188   19  Flat

And here is the function:
GenerateRF <- function(db, countstable, RFcutoff) {  

'load required libraries'
  library(RODBC)
  library(randomForest)
  library(caret)
  library(ff)
  library(stringi)

'connection and data preparation'
  connection <- odbcConnect ('TTODBC', uid='root', pwd='password', case="nochange")

'import count table and check if RF is allowed to be built'
  query.str <- paste0 ('select * from ', db, '.',  countstable, ' order by RowCount asc')
      row.counts <- sqlQuery (connection, query.str)

'Operate only on tables that have >= RFcutoff'
  for (i in 1:nrow (row.counts)) {
    table.name <- as.character (row.counts[i,1])
    col.count <- as.numeric (row.counts[i,2])
    row.count <- as.numeric (row.counts[i,3])

    if (row.count >= 20) {

'Delete old RFs and DFs for input pattern'
    if (file.exists (paste0 (table.name, '_RF.Rdata'))) {
          file.remove (paste0 (table.name, '_RF.Rdata'))
    }
    if (file.exists (paste0 (table.name, '_DF.Rdata'))) {
          file.remove (paste0 (table.name, '_DF.Rdata'))
    }

'import and clean data'
      query.str2 <- paste0 ('select * from ', db, '.',  table.name, ' order by mqltime asc')
          raw.data <- sqlQuery(connection, query.str2) 

'partition data into training/test sets'
      set.seed(489)
          index <- createDataPartition(raw.data$baXRC, p=0.66, list=FALSE, times=1)
              data.train <- raw.data [index,]
              data.test <- raw.data [-index,]

'find optimal trees to grow (without outcome and dates)
      data.mtry <- as.data.frame (tuneRF (data.train [, c(-1,-col.count)], data.train$baXRC, ntreetry=100,
                 stepFactor=.5, improve=0.01, trace=TRUE, plot=TRUE, dobest=FALSE)) 
          best.mtry <- data.mtry [which (data.mtry[,2] == min (data.mtry[,2])), 1]

'compress df'
      data.ff <- as.ffdf (data.train)

'run RF.  Originally set to 1000 trees but M1 dataset is to large for laptop.  Maybe train at the lab?' 
      data.rf <- randomForest (baXRC~., data=data.ff[,-1], mtry=best.mtry, ntree=500, keep.forest=TRUE,
               importance=TRUE, proximity=FALSE)

'generate and print variable importance plot'
      varImpPlot (data.rf, main = table.name)

'predict on test data'
      data.test.pred <- as.data.frame( predict (data.rf, data.test, type="prob"))

'get dates and name date column'
      data.test.dates <- data.frame (data.test[,1])
          colnames (data.test.dates) <- 'MQLTime'

'attach dates to prediction df'
      data.test.res <- cbind (data.test.dates, data.test.pred)

'force date coercion to attempt negating unambiguous format error '
      data.test.res$MQLTime <- format(data.test.res$MQLTime, format = "%Y-%m-%d %H:%M:%S")

'delete row names, coerce to dataframe, generate row table name and export outcomes to MySQL'
      rownames (data.test.res)<-NULL
      data.test.res <- as.data.frame (data.test.res)
      root.table <- stri_sub(table.name, 0, -5)
          sqlUpdate (connection, data.test.res, tablename = paste0(db, '.',  root.table, '_outcome'), index = "MQLTime")

'save RF and test df/s for future use; save latest version of row_counts to MQL4 folder'
      save (data.rf, file = paste0 ("C:/Users/user/Documents/RF_test2/", table.name, '_RF.Rdata'))
      save (data.test, file = paste0 ("C:/Users/user/Documents/RF_test2/", table.name, '_DF.Rdata'))
      write.table (row.counts, paste0("C:/Users/user/AppData/Roaming/MetaQuotes/Terminal/71FA4710ABEFC21F77A62A104A956F23/MQL4/Files/", db, "_m1_rowcounts.csv"), sep = ",", col.names = F, 
        row.names = F, quote = F)

'end of conditional block'
    }

'end of for loop'
  }

'close all connection to MySQL'
  odbcCloseAll()

'clear workspace'
  rm(list=ls())

'end of function'  
}

At this line: 
data.test.res$MQLTime <- format(data.test.res$MQLTime, format = "%Y-%m-%d %H:%M:%S")

I have tried coercing MQLTime using various functions including: as.character(), as. POSIXct(), as. POSIXlt(), as. Date(), format(), as.character(as. Date()) 
and have also tried:
"%y" vs "%Y" and "%OS" vs "%S"

All variants seem to have no effect on the error and the function is still able to run on all other tables.  I have checked the table manually (which contains almost 1500 rows) and also in MySQL looking for NULL dates or dates like "0000-00-00 00:00:00". 
Also, if I run the function line by line in R terminal, this offending table is processed without any problems which just confuses the hell out me. 
I've exhausted all the functions/solutions I can think of (and also all those I could find through Dr. Google) so I am pleading for help here. 
I should probably mention that the MQLTime column is stored as varchar() in MySQL.  This was done to try and get around issues with type conversions between R and MySQL
SHOW VARIABLES LIKE "%version%";
innodb_version, 5.6.19
protocol_version, 10
slave_type_conversions, 
version, 5.6.19
version_comment, MySQL Community Server (GPL)
version_compile_machine, x86
version_compile_os, Win32

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)

Edit: Str() output on the data as imported from MySQl showing MQLTime is already in POSIXct format:
> str(raw.data)
'data.frame':   1472 obs.  of  8 variables:
 $ MQLTime: POSIXct, format: "2014-11-05 23:35:00" "2014-11-05 23:57:00" "2014-11-06 00:40:00" "2014-11-06 00:46:00" ...
 $ bar5   : int  184 203 179 28 309 24 156 48 309 437 ...
 $ bar4   : int  24 184 309 192 48 177 48 68 60 71 ...
 $ bar3   : int  8 204 49 60 9 64 68 27 192 147 ...
 $ bar2   : int  24 67 189 49 11 152 27 56 437 67 ...
 $ bar1   : int  67 51 75 152 24 188 56 147 71 0 ...
 $ pat1   : int  147 147 19 147 19 19 147 19 147 19 ...
 $ baXRC  : Factor w/ 3 levels "Down","Flat",..: 2 2 2 2 2 2 2 2 2 3 ...

So I have tried declaring stringsAsfactors = FALSE in the dataframe operations and this had no effect. 
Interestingly, if the offending table is removed from processing through an additional conditional statement in the first 'if' block, the function stops on the table immediately preceeding the blocked table.  
If both the original and the new offending tables are removed from processing, then the function stops on the table immediately prior to them.  I have never seen this sort of behavior before and it really has me stumped. 
I watched system resources during the function and they never seem to max out. 
Could this be a problem with the 'for' loop and not necessarily date formats? 

A:

There appears to be some egg on my face.  The table following the table where the function was stopping had a row with value '0000-00-00 00:00:00'.  I added another statement in my MySQL function to remove these rows when pre-processing the tables.  Thanks to those that had a look at this.