AuthorMessage
Meka][Meka
Unstopable
Posts: 700

anyone wanna make some examples of mysql and delphi or jus mysql syntax in general?, wud be appreciated
bluebear
n00b
Posts: 32

The SQL syntax is well documented at mysql.com so i wont tell you about that.
And i dont work with delphi.. but heres a sample from PMspy wich is C++. DB part is C though..
The table:
Code:
CREATE TABLE `pmspy`.`pms` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `timestamp` DATETIME NOT NULL DEFAULT 0,
  `IP_from` VARCHAR(16) NOT NULL DEFAULT '',
  `IP_to` VARCHAR(16) NOT NULL DEFAULT '',
  `nick_to` TEXT NOT NULL DEFAULT '',
  `nick_from` TEXT NOT NULL DEFAULT '',
  `message` TEXT NOT NULL DEFAULT '',
  PRIMARY KEY(`id`)
)
ENGINE = MYISAM;

Includes
Code:
#include <mysql.h>

mysql state
Code:
static MYSQL mys;

Connect
Code:

  printf("Connecting to mysql...\n");
  if(!mysql_real_connect(&mys, addy, user, pass, db, port, NULL, 0))
  {
    printf(mysql_error(&mys));
    return false;
  }
  printf("Connected!\n");
  return true;

escape bad chars and insert in table
Code:

  m = malloc(strlen(message)*2);
  datasize += mysql_real_escape_string(&mys, m, message, strlen(message));
  query=malloc(datasize+255); /*Make sure we have enough space for the query */
  sprintf(query, "INSERT INTO pms(timestamp,IP_from,IP_to,nick_to,nick_from,message) VALUES('%s','%s','%s','%s','%s','%s');\0", t, i_f, it, nt, nf, m); /* Build query */
  if(mysql_real_query(&mys, query, strlen(query)))
  { // error }

close
Code:
mysql_close(&mys);

Mickey
Ametuar
Posts: 115

ZeosLIB has made an open source  component package called ZeosDBO. Working with MySQL is easy with this package. We are using this library at work for our MySQL projects.
Description:
The ZeosLib is a set of database components for MySQL, PostgreSQL, Interbase, Firebird, MS SQL, Sybase, Oracle and SQLite for Delphi, FreePascal/Lazarus, Kylix and C++ Builder.
Meka][Meka
Unstopable
Posts: 700

Quoted from Mickey
ZeosLIB has made an open source  component package called ZeosDBO. Working with MySQL is easy with this package. We are using this library at work for our MySQL projects.

jupp trying it, and its great, thanks... the dbexpress was buggy hence i cudnt get it to work....
Mickey
Ametuar
Posts: 115

I just want to let all users know who use ZeosLIB that there is an updated version of this package. It is beta but works fine for me.
Meka][Meka
Unstopable
Posts: 700

which version ?
Mickey
Ametuar
Posts: 115

Quoted from Meka][Meka
which version ?

Zeos Database Objects: zeosdbo-6.6.0-beta
Released: October 25, 2006