Giter VIP home page Giter VIP logo

connector-c-examples's People

Contributors

hholzgra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

connector-c-examples's Issues

Project build with run. (windows and linux)

Hi.
I wrote the following code based on your MySQL access demo.
I want to run this to create a database.
Please give me some advice to build this program.
Written in *.c in Visual Studio 2019.
Is it executable in Visual Studio 2019?
Which field of Visual Studio 2019 should you try to create?
What is MySQL library?
Isn't my.CNF file possible in Ubuntu system?
How do I build and run this on Ubuntu?
Please explain it step by step.
Thank you.

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timerfd.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <netdb.h>
#include <time.h>
#include <netinet/in.h>
#include <mysql.h>
#include <curl/curl.h>
#include <ctype.h>

MYSQL *mysql_con;

void
mysql_start()
{
mysql_con = mysql_init(NULL);
if (mysql_con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(mysql_con));
exit(1);
}

if (mysql_real_connect(mysql_con, "localhost", "happy", "123456", "happy", 0, NULL, 0) == NULL)
{
	fprintf(stderr, "%s\n", mysql_error(mysql_con));
	exit(EXIT_FAILURE);
}

if (mysql_query(mysql_con, "CREATE TABLE IF NOT EXISTS `frontier` (`url` varchar(2084) NOT NULL, `id` int NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), UNIQUE KEY `url` (`url`)) ENGINE=InnoDB AUTO_INCREMENT=1"))
{
	fprintf(stderr, "%s\n", mysql_error(mysql_con));
	mysql_stop();
            exit(1);
}

if (mysql_query(mysql_con, "CREATE TABLE IF NOT EXISTS `crawled` (`id` int NOT NULL AUTO_INCREMENT, `url` varchar(2084) DEFAULT NULL, `title` varchar(768) DEFAULT NULL, `date` varchar(128) DEFAULT NULL, `last_modified` varchar(128) DEFAULT NULL, `links` int DEFAULT NULL, `backlinks` int DEFAULT NULL, `http_code` int DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `url` (`url`), KEY `http_code` (`http_code`), KEY `title` (`title`)) ENGINE=InnoDB AUTO_INCREMENT=1"))
{
	fprintf(stderr, "%s\n", mysql_error(mysql_con));
            mysql_stop();
            exit(1);
}

if (mysql_query(mysql_con, "CREATE TABLE IF NOT EXISTS `emails` (`email` varchar(2084) NOT NULL, `id` int NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1"))
{
	fprintf(stderr, "%s\n", mysql_error(mysql_con));
            mysql_stop();
            exit(1);
}

}
void
mysql_stop()
{
mysql_close(mysql_con);
}
int
main(int argc, char **argv)
{
int cleanup = 0, opt, ret;

mysql_start();
mysql_stop();


printf("Exiting.\n");

return (0);

}

MIT license?

For learning resources such as examples maybe a very permissive license such as MIT would be a better fit?

mysql_real_escape_string example does not show how to avoid buffer overflow

I'm not sure if it is fair to raise an issue report here...

The mysql_real_escape_string example does not show how to avoid a buffer overflow on to. The best I can tell, the function is unsafe because it does not take a destination buffer size. Attacker controlled input to the function can simply enlist enough escapes to exceed the 201 character destination buffer.

For convenience here is the function:

const char *from = "\\";
char to[201];
unsigned long len;

len = mysql_real_escape_string(mysql, to, from, strlen(from));
to[len] = '\0';
printf("Escaped string is: \"%s\" (%lu)\n", to, len);

My apologies if I am parsing things incorrectly.

(I'm here because the MySQL example seems to have the same problem, and the MariaDB example does not exist).

Check for mariadb_config in addition to mysql_config

When using libmariadb dev packages only mariadb_config gets installed by default, mysql_config gets created as a symlink to mariadb_config only if libmariadb-dev-compat is also installed

The autoconf macros should check for both names

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.