Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I got a working solution now. Here's a function that maps MySQL field types to R classes. This helps in particular handling the MySQL field type date...</p> <pre><code>dbReadMap &lt;- function(con,table){ statement &lt;- paste("DESCRIBE ",table,sep="") desc &lt;- dbGetQuery(con=con,statement)[,1:2] # strip row_names if exists because it's an attribute and not real column # otherweise it causes problems with the row count if the table has a row_names col if(length(grep(pattern="row_names",x=desc)) != 0){ x &lt;- grep(pattern="row_names",x=desc) desc &lt;- desc[-x,] } # replace length output in brackets that is returned by describe desc[,2] &lt;- gsub("[^a-z]","",desc[,2]) # building a dictionary fieldtypes &lt;- c("int","tinyint","bigint","float","double","date","character","varchar","text") rclasses &lt;- c("as.numeric","as.numeric","as.numeric","as.numeric","as.numeric","as.Date","as.character","as.character","as.character") fieldtype_to_rclass = cbind(fieldtypes,rclasses) map &lt;- merge(fieldtype_to_rclass,desc,by.x="fieldtypes",by.y="Type") map$rclasses &lt;- as.character(map$rclasses) #get data res &lt;- dbReadTable(con=con,table) i=1 for(i in 1:length(map$rclasses)) { cvn &lt;- call(map$rclasses[i],res[,map$Field[i]]) res[map$Field[i]] &lt;- eval(cvn) } return(res) } </code></pre> <p>Maybe this is not good programming practice – I just don't know any better. So, use it at your own risk or help me to improve it... And of course it's only half of it: <code>reading</code>. Hopefully I´ll find some time to write a writing function soon.</p> <p>If you have suggestions for the mapping dictionary let me know :) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload