Private privStrConexao,privConexao privStrConexao="DRIVER=MySQL ODBC 3.51 Driver;" +; "SERVER=67.15.52.95;" +; "UID=myuser;" +; "PWD=mypassword;" +; "DATABASE=mydatabase;" +; "WSID="+Substr(Sys(0),1,Atc(Sys(0),"#")-1)+";" privConexao = Sqlstringconnect(privStrConexao) If privConexao < 1 Messagebox( 'wasn't connected ! '+allt(str(privConexao)),48,'Error' ) Else Wait window "Connected.." nowait Endif cPath_temporario = "f:\myssystem\dbfs" && place for local tables cwtab_only = "clients;" cwtab_desn = "gran_grade;email_list_;roteiros_itens;scripts;scripts_clientes;scripts_itens;tipos_respostas;empresa;roteiros;" && tables to remain only locally nwtot = ADIR(aFiles , cPath_temporario+iif(right(cPath_temporario,1)="\","","/")+"*.dbf") For i = 1 to alen(aFiles, 1) cwfile = forcepath(aFiles[i, 1], cPath_temporario) cwtb = lower(juststem(cwfile)) If cwtb+";"$cwtab_desn Loop Endif if empty(cwtab_only) else If cwtb+";"$cwtab_only else loop endif endif If file(cwfile) Sele 0 Use (cwfile) again alias tb_upload shared Else Loop Endif Sele tb_upload gnFieldcount = AFIELDS(gaMyArray) && Array with fields cwsqlfields = "" For nCount = 1 TO gnFieldcount If nCount > 1 cwsqlfields = cwsqlfields + ", " Endif cwsqlfields = cwsqlfields + lower(gaMyArray(nCount,1)) cwsqlf = "" Do case Case "dthr_ocorr"$lower(gaMyArray(nCount,1)) cwsqlf = " timestamp" Case gaMyArray(nCount,2) = "C" If gaMyArray(nCount,3)>1 cwsqlf = " varchar("+allt(str(gaMyArray(nCount,3)))+")" Else cwsqlf = " char("+allt(str(gaMyArray(nCount,3)))+")" Endif Case inlist(gaMyArray(nCount,2), "I", "N") If gaMyArray(nCount,4) = 0 If gaMyArray(nCount,3) > 3 cwsqlf = " tinyint("+allt(str(gaMyArray(nCount,3)))+")" Else cwsqlf = " int("+allt(str(gaMyArray(nCount,3)))+")" Endif Else cwsqlf = " dec("+allt(str(gaMyArray(nCount,3)))+", "+allt(str(gaMyArray(nCount,4)))+")" Endif Case gaMyArray(nCount,2) = "D" cwsqlf = " date" Case gaMyArray(nCount,2) = "T" cwsqlf = " datetime" Case gaMyArray(nCount,2) = "M" cwsqlf = " text" Case gaMyArray(nCount,2) = "L" cwsqlf = " tinyint(1)" Endcase cwsqlfields = cwsqlfields + cwsqlf Endfor If "campanhas"$cwtb .or. "log"$cwtb && some few exceptions cwsqlfields = "cliente varchar(5), " + cwsqlfields Endif * to create an expr with the index keys cwsqlkeys = "" wkeyexpr = "A" x = 1 wprefkey = "" For nCount = 1 TO 254 If !EMPTY(TAG(nCount)) && Verifica se há marcas no índice *cwstrmk = iif(type("TAG(nCount)")="C", "'", "") cwkey = ""+lower(KEY(nCount))+"" if "+"$cwkey do while "+"$cwkey cwkey = stuff(cwkey,at("+",cwkey),1,", ") enddo endif if "ttoc("$cwkey do while "ttoc("$cwkey nwpos = at("ttoc(",cwkey) cwkey = stuff(cwkey, nwpos,5,"") if at(",1)",cwkey) > 0 nwpos = at(",1)",cwkey) cwkey = stuff(cwkey, nwpos, 3,"") endif enddo endif if "substr("$cwkey do while "substr("$cwkey nwpos = at("substr(",cwkey) cwkey = stuff(cwkey, nwpos,7,"") if at(",1,8)",cwkey) > 0 nwpos = at(",1,8)",cwkey) cwkey = stuff(cwkey, nwpos, 5,"") endif enddo endif cwsqlkeys = cwsqlkeys + ", KEY " + lower(TAG(nCount)) + " (" + cwkey + ") " Else Exit Endif Endfor *cwsqlstring = "CREATE TABLE "+cwtb+" ("+cwsqlfields+cwsqlkeys+")" cwsqlstring = "CREATE TABLE "+cwtb+" ("+cwsqlfields+")" nwret=SQLexec(privConexao, cwsqlstring) Do while nwret = 0 Enddo Sele tb_upload Use Endfor SQLDISCONNECT(privConexao)HTH