C com MySQL [RESOLVIDO]

1. C com MySQL [RESOLVIDO]

vinicius
vinicius_souza

(usa Ubuntu)

Enviado em 06/12/2012 - 18:16h

Pessoal,
Alguem ai me indica uma apostila para conectar o C em MySQL e fazer as operações básicas, INSERT INTO, UPDATE, DROP, SELECT?
Uma apostila ou um código já pronto para eu analizar as funções? ou até mesmo uma biblioteca?
Att:Vinícius


  


2. Re: C com MySQL [RESOLVIDO]

Daniel Lara Souza
danniel-lara

(usa Fedora)

Enviado em 06/12/2012 - 18:53h

de uma lida
http://www.vivaolinux.com.br/artigo/Usando-MySQL-na-linguagem-C

espero que ajude


3. Re: C com MySQL [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 09/12/2012 - 11:30h


talvez vc goste do SQLite3 pela simplicidade e tamanho reduzido, veja um pequeno exemplo:

esse exemplo cria uma tabela e cadastra o primeiro "cliente" ... ou se executado pela segunda vez adiciona "mais cliente(o mesmo criante, ;))"




#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

sqlite3 *db;
int rc;
char buf[255];


int main (int argc, char *argv[])
{
if (argc != 2) {
printf ("Usage: %s file.db\n", argv[0]);
return -1;
}

rc = sqlite3_open (argv[1], &db);

if (rc) {
printf ("Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close (db);
return -1;
}

//---------------------------------------------------------------
//
// cria a tabela ( pessoa ) com 2 colunas ( col0, col1 ) ...
//
// col0: int
// col1: "string"
//
//---------------------------------------------------------------
sprintf (buf, "CREATE TABLE IF NOT EXISTS pessoa(col0 INTEGER, col1 TEXT)");
sqlite3_exec (db, buf, 0, 0, 0);

//---------------------------------------------------------------
//
// primeiro cadastro ...
//
//---------------------------------------------------------------
sprintf (buf, "INSERT INTO pessoa VALUES(1, 'nome_primeira_pessoa')");
sqlite3_exec (db, buf, 0, 0, 0);

sqlite3_close (db);

return 0;
}




mais detalhes: http://www.sqlite.org/




4. Re: C com MySQL [RESOLVIDO]

André
andrezc

(usa Debian)

Enviado em 09/12/2012 - 18:33h

Se quiser um exemplo prático com tudo isso, dê uma olhada no meu script:
http://vivaolinux.com.br/script/Agenda-completa-em-C-com-SQL


5. Re: C com MySQL [RESOLVIDO]

vinicius
vinicius_souza

(usa Ubuntu)

Enviado em 10/12/2012 - 14:43h

Na primeira reposta entrei no link e fui tentar compilar para eu entender e colocar no meu cód.
Compilei esse programa com o Dev C++

#include <stdio.h>
#include <mysql/mysql.h>

#define HOST "localhost"
#define USER "guest"
#define PASS "guest"
#define DB "teste"

int main(void)
{
MYSQL conexao;
MYSQL_RES *resp;
MYSQL_ROW linhas;
MYSQL_FIELD *campos;
char query[]="SELECT * FROM aprendendo;";
int conta; //Contador comum

mysql_init(&conexao);
if (mysql_real_connect(&conexao,HOST,USER,PASS,DB,0,NULL,0))
{
printf("Conectado com Sucesso!\n");
if (mysql_query(&conexao,query))
printf("Erro: %s\n",mysql_error(&conexao));
else
{
resp = mysql_store_result(&conexao);//recebe a consulta
if (resp) //se houver consulta
{
//passa os dados dos campos para a variável campos
//escreve na tela os nomes dos campos dando
//um tab somente
campos = mysql_fetch_fields(resp);
for (conta=0;conta<mysql_num_fields(resp);conta++) {
printf("%s",(campos[conta]).name);
if (mysql_num_fields(resp)>1)
printf("\t");
}

printf("\n");

//enquanto retonrnar registros, conta até o
//número de colunas que a tabela tem e escreve na
//tela com um tab, depois pula a linha e tenta
//pegar outro registro
while ((linhas=mysql_fetch_row(resp)) != NULL)
{
for (conta=0;conta<mysql_num_fields(resp);conta++)
printf("%s\t",linhas[conta]);
printf("\n");
}
}
mysql_free_result(resp);//limpa a variável do resultado: resp
}
mysql_close(&conexao);
}
else
{
printf("Conexao Falhou\n");
if (mysql_errno(&conexao))
printf("Erro %d : %s\n", mysql_errno(&conexao), mysql_error(&conexao));
}

return 0;
}


só que deu os seguintes erros.

Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c" -o "C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:/Dev-Cpp/include/mysql/mysql.h:57,
from C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:2:
C:/Dev-Cpp/include/mysql/mysql_com.h:175: error: syntax error before "SOCKET"
C:/Dev-Cpp/include/mysql/mysql_com.h:175: warning: no semicolon at end of struct or union

C:/Dev-Cpp/include/mysql/mysql_com.h:208: error: syntax error before '}' token

C:/Dev-Cpp/include/mysql/mysql_com.h:208: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql_com.h:321: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:322: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:323: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:324: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:325: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:326: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:327: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:328: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:331: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:332: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql_com.h:339: error: syntax error before "s"

In file included from C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:2:
C:/Dev-Cpp/include/mysql/mysql.h:237: error: syntax error before "NET"
C:/Dev-Cpp/include/mysql/mysql.h:237: warning: no semicolon at end of struct or union

C:/Dev-Cpp/include/mysql/mysql.h:262: error: 'scramble' redeclared as different kind of symbol

C:/Dev-Cpp/include/mysql/mysql_com.h:407: error: previous declaration of 'scramble' was here
C:/Dev-Cpp/include/mysql/mysql.h:262: error: 'scramble' redeclared as different kind of symbol
C:/Dev-Cpp/include/mysql/mysql_com.h:407: error: previous declaration of 'scramble' was here
C:/Dev-Cpp/include/mysql/mysql.h:287: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql/mysql.h:287: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:295: error: syntax error before "MYSQL"
C:/Dev-Cpp/include/mysql/mysql.h:295: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql/mysql.h:304: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql/mysql.h:304: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:322: error: syntax error before "NET"
C:/Dev-Cpp/include/mysql/mysql.h:322: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql/mysql.h:328: error: conflicting types for 'last_errno'
C:/Dev-Cpp/include/mysql/mysql_com.h:203: error: previous declaration of 'last_errno' was here
C:/Dev-Cpp/include/mysql/mysql.h:331: error: conflicting types for 'last_error'

C:/Dev-Cpp/include/mysql/mysql_com.h:202: error: previous declaration of 'last_error' was here

C:/Dev-Cpp/include/mysql/mysql.h:332: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql/mysql.h:332: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:380: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:381: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:382: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:383: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:385: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:386: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:387: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:389: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:390: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:391: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:392: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:393: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:394: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:395: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:396: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:397: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:398: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:399: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:401: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:401: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:401: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:402: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:405: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:407: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:407: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:413: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:414: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:415: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:416: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:418: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:420: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:420: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:420: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:421: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:421: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql/mysql.h:421: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:424: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:426: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:429: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:431: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:433: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:441: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:443: error: `mysql_set_local_infile_handler' declared as function returning a function
C:/Dev-Cpp/include/mysql/mysql.h:444: error: syntax error before "int"
C:/Dev-Cpp/include/mysql/mysql.h:452: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:459: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:460: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:462: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:465: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:466: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:468: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:473: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:476: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:480: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:485: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:488: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:489: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:491: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:492: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:495: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:496: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:497: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:500: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:501: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:502: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:503: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:503: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:503: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:504: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:504: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:504: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:505: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:505: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:505: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:506: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:508: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:509: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:511: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:513: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:515: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:516: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:517: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:518: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:518: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:519: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:524: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:528: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:537: error: syntax error before ')' token
C:/Dev-Cpp/include/mysql/mysql.h:538: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:541: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:541: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:541: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:542: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:542: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:546: warning: data definition has no type or storage class

C:/Dev-Cpp/include/mysql/mysql.h:547: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:548: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:550: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:553: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql/mysql.h:651: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:664: error: syntax error before "MYSQL"
C:/Dev-Cpp/include/mysql/mysql.h:664: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql/mysql.h:687: error: conflicting types for 'last_errno'
C:/Dev-Cpp/include/mysql/mysql.h:328: error: previous declaration of 'last_errno' was here
C:/Dev-Cpp/include/mysql/mysql.h:687: error: conflicting types for 'last_errno'
C:/Dev-Cpp/include/mysql/mysql.h:328: error: previous declaration of 'last_errno' was here
C:/Dev-Cpp/include/mysql/mysql.h:691: error: conflicting types for 'last_error'
C:/Dev-Cpp/include/mysql/mysql.h:331: error: previous declaration of 'last_error' was here
C:/Dev-Cpp/include/mysql/mysql.h:691: error: conflicting types for 'last_error'
C:/Dev-Cpp/include/mysql/mysql.h:331: error: previous declaration of 'last_error' was here
C:/Dev-Cpp/include/mysql/mysql.h:704: error: syntax error before '}' token
C:/Dev-Cpp/include/mysql/mysql.h:704: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:731: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:732: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:739: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:741: warning: no semicolon at end of struct or union
C:/Dev-Cpp/include/mysql/mysql.h:744: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:746: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:747: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:748: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:749: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:750: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:751: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:752: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:753: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:754: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:756: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:759: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:759: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:759: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:760: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:762: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:763: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:764: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:767: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:768: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:769: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:772: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:775: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:776: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:777: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:778: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:779: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:780: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:784: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:784: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:784: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:785: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:785: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:785: warning: data definition has no type or storage class
C:/Dev-Cpp/include/mysql/mysql.h:786: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:787: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:788: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:789: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:791: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:792: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:793: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:794: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:795: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:796: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:798: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql/mysql.h:799: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:800: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:801: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:802: error: syntax error before '*' token

C:/Dev-Cpp/include/mysql/mysql.h:803: error: syntax error before '*' token
C:/Dev-Cpp/include/mysql/mysql.h:829: error: syntax error before '*' token
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c: In function `main':
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:11: error: syntax error before "conexao"
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:12: error: `resp' undeclared (first use in this function)
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:12: error: (Each undeclared identifier is reported only once
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:12: error: for each function it appears in.)
C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c:18: error: `conexao' undeclared (first use in this function)

Execution terminated

No caso do sqlite3 compilei esse cód.

#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

sqlite3 *db;
int rc;
char buf[255];


int main (int argc, char *argv[])
{
if (argc != 2) {
printf ("Usage: %s file.db\n", argv[0]);
return -1;
}

rc = sqlite3_open (argv[1], &db);

if (rc) {
printf ("Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close (db);
return -1;
}

//---------------------------------------------------------------
//
// cria a tabela ( pessoa ) com 2 colunas ( col0, col1 ) ...
//
// col0: int
// col1: "string"
//
//---------------------------------------------------------------
sprintf (buf, "CREATE TABLE IF NOT EXISTS pessoa(col0 INTEGER, col1 TEXT)");
sqlite3_exec (db, buf, 0, 0, 0);

//---------------------------------------------------------------
//
// primeiro cadastro ...
//
//---------------------------------------------------------------
sprintf (buf, "INSERT INTO pessoa VALUES(1, 'nome_primeira_pessoa')");
sqlite3_exec (db, buf, 0, 0, 0);

sqlite3_close (db);

return 0;
}

e deu esses erros.

Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.c" -o "C:\Users\vinicius.CRISTIANO\Desktop\Acessa MySQL\ex1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0x65):ex1.c: undefined reference to `sqlite3_open'
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0x80):ex1.c: undefined reference to `sqlite3_errmsg'
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0x9d):ex1.c: undefined reference to `sqlite3_close'
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0xea):ex1.c: undefined reference to `sqlite3_exec'
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0x12b):ex1.c: undefined reference to `sqlite3_exec'
C:\Users\VINICI~1.CRI\AppData\Local\Temp/ccOUbaaa.o(.text+0x138):ex1.c: undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status

Execution terminated

Att:Vinícius


6. Re: C com MySQL [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 10/12/2012 - 17:24h

no segundo codigo usando SQLite3 faltou apenas linkar:

faca o seguinte:

Pegue no site ( http://www.sqlite.org/download.html ) o arquivo para windows que tem o DLL e compile assim:
-----------------------------------
gcc programa.c -o programa sqlite3.dll -Wall
-----------------------------------

ou poderia linkar com o proprio codigo ( sqlite3.c ) mas neste caso o seu programa ficaria GRANDinho ...

DICA: e aprenda a ficar familiar com o "console"(MS-DOS) do windows ...


7. Re: C com MySQL [RESOLVIDO]

vinicius
vinicius_souza

(usa Ubuntu)

Enviado em 10/12/2012 - 17:46h

Obrigado gokernel, funcionou.
Porém agora tenho duas duvidas.
1ª Os comandos do MySQL são da mesma forma no SQLLITE? (UPDATE,SELECT,INSERT INTO, DROP).
2ª Qual resposta sua eu marco com melhor ? kkk =(
EDITADO ------------------------------------
O sqlite grava no banc de dados MySQL?
EDITADO ------------------------------------


8. Re: C com MySQL [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 10/12/2012 - 18:25h

olá "vinicius", fico feliz por ajudar a resolver o seu problema !

1ª Os comandos do MySQL são da mesma forma no SQLLITE? (UPDATE,SELECT,INSERT INTO, DROP).

RESPOSTA:
Sim, sao os mesmos comandos mas nao tenho certeza se sao da mesma forma.

2ª Qual resposta sua eu marco com melhor ? kkk =(

RESPOSTA:
Qual vc achou melhor ? ;)

O sqlite grava no banc de dados MySQL?

RESPOSTA:
Nao tenho certeza, em caso de dúvida acho melhor utilizar cada "banco" com seu uso.

INFO: mais tarde quando chegar em casa a noite posto o resto do codigo para mostrar os dados no banco ja cadastrado .


9. Re: C com MySQL [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 10/12/2012 - 19:41h


essa foi a forma mais simples que achei para demonstrar ( cadastrar e listar ):

http://codepad.org/WlGDcRDU




10. Re: C com MySQL [RESOLVIDO]

vinicius
vinicius_souza

(usa Ubuntu)

Enviado em 10/12/2012 - 19:57h

On de que eu peço para criar o banco de dados?


11. Re: C com MySQL [RESOLVIDO]

???
gokernel

(usa Linux Mint)

Enviado em 10/12/2012 - 20:08h


@Vinicius:
"Onde que eu peço para criar o banco de dados?"

nao entendi direito a pergunta, vc se refere ao local/pasta ???

fica a seu criterio de organizacao da pasta do banco de dados.

no codigo que postei linha ( 68 ) cria/abre o seu banco de dados:
------------------------------------------
rc = sqlite3_open (argv[1], &db);
------------------------------------------

nao sei se respondi a sua pergunta pois tambem nao entendi direito ... POR HOJE EH SO ... DESLIGANDO O NOTE 3, 2, 1, 0


12. Re: C com MySQL [RESOLVIDO]

vinicius
vinicius_souza

(usa Ubuntu)

Enviado em 11/12/2012 - 13:31h

Não é o local mas sim no programa (CREATE DATABASE vinicius;) por exemplo, no código faz isso?Lá em cima vi um USAGE: programa data.db seria uma instrução a parte que eu deveria fazer?
Depois de compilado eu tenho que levar o arquivo "sqlite3.exe" para dentro do diretório Windows do usuário ou é só no meu na hora de compilar?
E esse por exemplo INSERT INTO que você colocou (sprintf (buf, "INSERT INTO pessoa VALUES (1, 'Vania', 123)");) você já predefiniu o nome da pessoa e a idade, mas seu eu quiser por exemplo que o usuário digite um nome qualquer e salve na tabela, como seria?sprintf (buf, "INSERT INTO pessoa VALUES (1, \"cadastra_nome\", 123)"),%s; ficaria assim?.
Desde já agradeço.
Att:Vinícius



01 02



Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts