PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV Mobile 2024
→
Carga Txt To Sql
Carga Txt To Sql
Started by adrianoboller, Nov., 18 2014 1:49 PM - 1 reply
Connect yourself…
adrianoboller
#1
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on November, 18 2014 - 1:49 PM
Procedure
DB_CargaTxt2Sql
(
LOCAL
ArquivoTxt
,
LOCAL
TabelaSQL
,
LOCAL
Excluir
,
LOCAL
Debug
)
// Finalidade é ler um txt que se encontra na raiz do aplicativo e importar os dados para a base de dados do aplicativo android como carga inicial.
// Declara as variaves
IdFile
,
ResCloseFile
,
FileID
,
NumeroLinha is
int
Line is
string
Resultado is
boolean
QRYSQL is
Data Source
//Verifica se existe o arquivo
PathFile is
string
=
fDataDir
(
) + [
"\"
] +
ArquivoTxt
IF
NOT
fFileExist
(
PathFile
)
THEN
Close
(
)
END
//Abrir arquivo txt
FileID
=
fOpen
(
PathFile
,
foReadWrite
)
IF
IdFile
= -
1
THEN
NextTitle
(
"Atenção"
)
Error
(
ErrorInfo
(
errMessage
)
)
ELSE
//Converte de Unicode para Ansi
Line
=
UnicodeToAnsi
(
fReadLine
(
FileID
)
)
//Limpa Base de dados
IF
Excluir
=
"S"
THEN
Resultado
=
HExecuteSQLQuery
(
QRYSQL
,
"Delete from "
+
TabelaSQL
)
IF
Resultado
=
True
AND
TabelaSQL
<
>
""
THEN
IF
Debug
=
"S"
THEN
NextTitle
(
"Atenção"
)
Info
(
"Tabela "
+
TabelaSQL
+
" inicializada."
)
END
END
END
//Leitura do Arquivo
//Linha 1 = OBS do Arquivo Finalidade da Carga
NumeroLinha
=
0
WHILE
Line
<
>
EOT
AND
Line
<
>
""
//Proxima linha
NumeroLinha
+
=
1
Line
=
fReadLine
(
FileID
)
IF
Debug
=
"S"
THEN
Info
(
"Linha:"
+
NumeroLinha
,
Line
)
END
//Insere os dados do arquivo texto na Nova Base de Dados
Resultado
=
HExecuteSQLQuery
(
QRYSQL
,
Line
)
IF
Resultado
=
False
AND
Line
<
>
""
AND
Length
(
Line
) >
3
THEN
NextTitle
(
"Atenção"
)
Info
(
"Erro no arquivo de carga!..."
,
Line
)
ELSE
IF
Debug
=
"S"
THEN
NextTitle
(
"Atenção"
)
Info
(
"Carga da base de dados com sucesso!"
,
Line
)
Info
(
HNbRec
(
TabelaSQL
,
hStateAll
) )
END
END
END
//Final do Arquivo
IF
Debug
=
"S"
THEN
IF
Line
=
""
THEN
Error
(
ErrorInfo
(
errMessage
)
)
IF
Line
=
EOT
THEN
Info
(
"Final do Arquivo."
)
NextTitle
(
"Atenção"
)
Info
(
"Registros gravados na tabela "
+
TabelaSQL
,
HNbRec
(
TabelaSQL
,
hStateAll
)
)
END
//Fechando a leitura do Arquivo
ResCloseFile
=
fClose
(
IdFile
)
IF
ResCloseFile
=
0
THEN
IF
Debug
=
"S"
THEN
Error
(
"Arquivo fechado com sucesso!"
)
END
END
END
Report
0
0
adrianoboller
#2
Registered member
3,659 messages
Popularité : +175 (223 votes)
Posted on March, 24 2016 - 8:45 PM
Prezados,
Caso de problema com acentuação, use:
Esse comando chegou a testar?
retorno is string = UFT8toString(textocomacento)
USE O COMANDO UTF8ToString OU AnsiToUnicode
ProcedureWS_Android_IOS_HTTPGetResult
(
)
// Variable
buf
ResHTTP is Buffer
s
HTTPResult isstring
// Retrieves the result of the query
buf
ResHTTP
=
HTTPGetResult
(
httpResult
)
// Result in UTF8 em iOS Apple
IFIniOSMode
(
) =
TrueORIniOSSimulatorMode
(
) =
TrueORIniOSEmulatorMode
(
) =
True
IFStringCount
(
buf
ResHTTP
, “
ISO
-
8859
-
1
”
,
IgnoreCase
) =
0
THEN
s
HTTPResult
=
UTF8ToString
(
buf
ResHTTP
)
ELSE
s
HTTPResult
=
AnsiToUnicode
(
buf
ResHTTP
)
END
ELSE
IFInAndroidMode
(
) =
TrueORInAndroidSimulatorMode
(
) =
TrueORInAndroidEmulatorMode
(
) =
True
// Result in Android
s
HTTPResult
=
buf
ResHTTP
END
RESULTsHTTPResult
--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.blogspot.com.br/
Report
0
0
→ Go back to WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text