樹心幽徑

20181030在ubuntu用c在mysql ilvssell資料庫建立new_outcome_detail資料表並加入一筆資料(t13.c)
2018/10/30,20:28

(1)程式碼:t13.c

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{

  MYSQL *con = mysql_init(NULL);
  if (con == NULL) {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "treehrt", "abc123abc123",
          "ilvssell", 0, NULL, 0) == NULL) {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  } 

  if (mysql_query(con, "DROP TABLE IF EXISTS new_outcome_detail")) {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }
  printf("DROP TABLE new_outcome_detail ok!\n");
  mysql_query(con, "set names utf8");

  char st[]="CREATE TABLE new_outcome_detail(flush int default 0,sheet char(20) primary key default '20181030A00001',custno char(10) default '-', goodsno char(20),price float,quantity int,itemno int,goodsname char(30),opday char(20) default '2018-10-30 20:25:00')";
 
  if (mysql_query(con, st)) {
      fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1);
  }
  printf("Execute[%s] ok!!\n", st);

  sprintf(st,"%s","insert into new_outcome_detail (flush,sheet,custno,goodsno,price,quantity,itemno,goodsname, opday) values (0,'20181030A00001','312001','a001',15,10,2,'蕃茄', '2018-10-30 20:25:00')");
  if (mysql_query(con, st)) {
      fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1);
  }
  printf("Execute[%s] ok!!\n", st);

  mysql_close(con);
  exit(0);
}

 

(2)編譯

$ gcc t13.c `mysql_config --cflags --libs`

 

(3)執行

$ ./a.out
DROP TABLE new_outcome_detail ok!
Execute[CREATE TABLE new_outcome_detail(flush int default 0,sheet char(20) primary key default '20181030A00001',custno char(10) default '-', goodsno char(20),price float,quantity int,itemno int,goodsname char(30),opday char(20) default '2018-10-30 20:25:00')] ok!!
Execute[insert into new_outcome_detail (flush,sheet,custno,goodsno,price,quantity,itemno,goodsname, opday) values (0,'20181030A00001','312001','a001',15,10,2,'蕃茄', '2018-10-30 20:25:00')] ok!!

 

(4)在mysql命令列檢視結果

mysql> desc new_outcome_detail;
+-----------+----------+------+-----+---------------------+-------+
| Field     | Type     | Null | Key | Default             | Extra |
+-----------+----------+------+-----+---------------------+-------+
| flush     | int(11)  | YES  |     | 0                   |       |
| sheet     | char(20) | NO   | PRI | 20181030A00001      |       |
| custno    | char(10) | YES  |     | -                   |       |
| goodsno   | char(20) | YES  |     | NULL                |       |
| price     | float    | YES  |     | NULL                |       |
| quantity  | int(11)  | YES  |     | NULL                |       |
| itemno    | int(11)  | YES  |     | NULL                |       |
| goodsname | char(30) | YES  |     | NULL                |       |
| opday     | char(20) | YES  |     | 2018-10-30 20:25:00 |       |
+-----------+----------+------+-----+---------------------+-------+
9 rows in set (0.00 sec)

mysql> select * from new_outcome_detail;
+-------+----------------+--------+---------+-------+----------+--------+-----------+---------------------+
| flush | sheet          | custno | goodsno | price | quantity | itemno | goodsname | opday               |
+-------+----------------+--------+---------+-------+----------+--------+-----------+---------------------+
|     0 | 20181030A00001 | 312001 | a001    |    15 |       10 |      2 | 蕃茄      | 2018-10-30 20:25:00 |
+-------+----------------+--------+---------+-------+----------+--------+-----------+---------------------+
1 row in set (0.00 sec)

mysql> quit

20181029在ubuntu用c在mysql ilvssell資料庫建立new_outcome資料表並加入一筆資料(t12.c)
2018/10/29,21:03

(1) 程式碼:

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat t12.c
#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());

  MYSQL *con = mysql_init(NULL);

  if (con == NULL)
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "treehrt", "abc123abc123",
          "ilvssell", 0, NULL, 0) == NULL)
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  } 

  if (mysql_query(con, "DROP TABLE IF EXISTS new_outcome"))
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }
  printf("DROP TABLE new_outcome ok!\n");
  mysql_query(con, "set names utf8");

  char st[]="CREATE TABLE new_outcome(flush int default 0,sheet char(20) primary key default '20181029A00001',custno char(10) default '-', amount int default 0,opday char(20) default '2018-10-29 20:25:00')";
  if (mysql_query(con, st)) {
      fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1);
  }
  printf("Execute[%s] ok!!\n", st);

  sprintf(st,"%s","insert into new_outcome (flush,sheet,custno,amount,opday) values (0,'20181029A00001','712003',550,'2018-10-29 20:25:00')");

  if (mysql_query(con, st)) {
      fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1);
  }
  printf("Execute[%s] ok!!\n", st);

  mysql_close(con);
  exit(0);
}

 

(2)編譯:

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc t12.c `mysql_config --cflags --libs`

(3)執行

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
DROP TABLE new_outcome ok!
Execute[CREATE TABLE new_outcome(flush int default 0,sheet char(20) primary key default '20181029A00001',custno char(10) default '-', amount int default 0,opday char(20) default '2018-10-29 20:25:00')] ok!!
Execute[insert into new_outcome (flush,sheet,custno,amount,opday) values (0,'20181029A00001','712003',550,'2018-10-29 20:25:00')] ok!!

 

(4)在mysql命令列查看

mysql> use ilvssell;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> desc new_outcome;
+--------+----------+------+-----+---------------------+-------+
| Field  | Type     | Null | Key | Default             | Extra |
+--------+----------+------+-----+---------------------+-------+
| flush  | int(11)  | YES  |     | 0                   |       |
| sheet  | char(20) | NO   | PRI | 20181029A00001      |       |
| custno | char(10) | YES  |     | -                   |       |
| amount | int(11)  | YES  |     | 0                   |       |
| opday  | char(20) | YES  |     | 2018-10-29 20:25:00 |       |
+--------+----------+------+-----+---------------------+-------+
5 rows in set (0.00 sec)

mysql> select * from new_outcome;
+-------+----------------+--------+--------+---------------------+
| flush | sheet          | custno | amount | opday               |
+-------+----------------+--------+--------+---------------------+
|     0 | 20181029A00001 | 712003 |    550 | 2018-10-29 20:25:00 |
+-------+----------------+--------+--------+---------------------+
1 row in set (0.00 sec)

 

20181026POS1收銀機系統第1步
2018/10/26,14:08

 

20181026POS1收銀機系統第1步

pos1.c code :    http://oldwww.kmvs.km.edu.tw/lf/index.php?op=ViewResource&blogId=70&resource=1719-pos1.c

pos.h include file:

http://oldwww.kmvs.km.edu.tw/lf/index.php?op=ViewResource&blogId=70&resource=pos.h

alt

20181016HEXDUMP.EXE
2018/10/16,14:17

(1) REF:

https://www.di-mgt.com.au/hexdump-for-windows.html

 

(2)下載 hexdump-2.0.0.zip並解開

 

20181010在ubuntu用c在mysql ilvssell資料庫new_id_reg資料表加入一筆資料(t11.c)
2018/10/10,21:30

(1) code : t11.c

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat t11.c
//gcc t11.c `mysql_config --cflags --libs`
#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());

  MYSQL *con = mysql_init(NULL);

  if (con == NULL)
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }


  if (mysql_real_connect(con, "localhost", "treehrt", "abc123abc123",
          "ilvssell", 0, NULL, 0) == NULL)
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  } 


 mysql_query(con, "set names utf8");

 char st[]="insert into new_id_reg (sta_no,inday,custno,money_store, saleno,remain,serial,oldremain) values ('A','2018-10-10 21:24:00','312001',5000, 'X',6100,'A2018101000001',1100)";
  printf("Prepare %s\n", st);

  if (mysql_query(con, st))
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }
  printf("Execute ok!  %s\n", st);

  mysql_close(con);

  exit(0);
}

 

(2)compile

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc t11.c `mysql_config --cflags --libs`

 

(3)執行

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
Prepare insert into new_id_reg (sta_no,inday,custno,money_store, saleno,remain,serial,oldremain) values ('A','2018-10-10 21:24:00','312001',5000, 'X',6100,'A2018101000001',1100)
Execute ok!  insert into new_id_reg (sta_no,inday,custno,money_store, saleno,remain,serial,oldremain) values ('A','2018-10-10 21:24:00','312001',5000, 'X',6100,'A2018101000001',1100)
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$

 

(4)用mysql命令列查詢結果

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ mysql -utreehrt -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ilvssell           |
+--------------------+
2 rows in set (0.00 sec)

mysql> use ilvssell;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------+
| Tables_in_ilvssell |
+--------------------+
| new_cust           |
| new_factory        |
| new_goods          |
| new_id_reg         |
+--------------------+
4 rows in set (0.00 sec)

mysql> select * from new_id_reg;
+--------+---------------------+--------+-------------+--------+--------+----------------+-----------+
| sta_no | inday               | custno | money_store | saleno | remain | serial         | oldremain |
+--------+---------------------+--------+-------------+--------+--------+----------------+-----------+
| A      | 2018-10-10 21:24:00 | 312001 |        5000 | X      |   6100 | A2018101000001 |      1100 |
+--------+---------------------+--------+-------------+--------+--------+----------------+-----------+
1 row in set (0.00 sec)

mysql> quit
Bye

 

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType