樹心幽徑

20180629openssl操作
2018/06/29,14:40

treehrt@hrt:~/mysqlc$ openssl genrsa -out server.key 2048

treehrt@hrt:~/mysqlc$ cat server.key
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAocpKIi6uVmkfOIWDcS3EQoB2eX8wQzU2pHK5PT5DptIIfk/c
TE9mP+Czx2rG7waU/ufSwKCppCqawA4RmSNezxLVPym8VuNdNfrxwzq3TM5Xn28L
4UkmT19uRhXC8+NrUblHvdcbg4P6PRUPLSwkUcev59v217Xp7jDIRP5mmL5K4xQS
X0CG7hb5sofgLxaWF5grw7W+PEhShY9o3E2/Ibo+I53S0Up2GxN3BXkpp3zWJ19o
CydqB4lIAQhKjDUz7Yee3Pen6+FHE6GMCwRMYci4mr/b8K30RlJUXWeTNOST1Ptq
0t/xTOOgwucjaGbcFoI8zp+0mzWdRxLh6gP2nQIDAQABAoIBAA1OY9Z33GLC9oxh
frP6PZ/yjMvlSATfBYV04gNFca7wqz4oN0gXZ6NtSZvnDkFuWyazzkOFcy5LSrrs
7UmY/R0uwVcWiaTjwjDEWMnjtFuexNoZ+fInX/07LgiZlZUVaSgpgtr8LAke+5+2
ca8XaE1JjRAWqTCIh5rNbEswWSPKsUPCO3rANsgUTgYGoKvTNA1TGsrZHu+cdkAz
2mT+8J3T5e0UZpB6lJjTbAtf4ZccGysXr7SB3MofMRGRXmbU9DCtLnmkhZebDTPh
Xt9mIfMQdk+ciAXAEooVHJ5EzMGZl8g+ZUK9jEhVvms72K70bDVo1LCjpgzVsIme
VQqKikECgYEA0iIjGug822D/+OnQ+Y9qcq+7LNKd8UaTPzexxoCaqhQGhEQ/o2C0
auddO8uXRp6e1VLKQIXLBiMSnyYWbTTkM5U1GIQuBk9lVacteuNO0PxKahhLeX+9
j6vKqrOmeAZCkzXAEXJECQvIjA9EsbWerl72lldPmb3wDHLZzrq/9/kCgYEAxRrT
jkNy7S0ArOQ7GEhJcuNL2DATcPlYd0w++KoZNza2rrZQ/54glYlkf3yRw4uvEIq7
97s9vdlyCyJzt+e7oJymiXE/dMUDvcym2e3P000PrBJrqau72W9TYnMROsuKeVzr
fEeu21dVFZrsosVAqqNDW4smXwtzGJqFs3zMRMUCgYArM72H8KtiZyT5ZgkC5gt6
nMqcwoiabGolmyu/pf0mbouQcf+rdVxihkLS4l6ttDrvnN/cOCWvk1JmygveU/t+
53RNIA/eWEB7Ra3CEC3KJbSe73PE/RBaE3XNdrYJAzB415ovfBCk03ld4l27M532
N6v26OiCsVxDEvHY4OhK8QKBgQChylJrTVwx6SXLxQ/o77Uyk/a2v0fGDTabvj9W
WDGYi9XKdabpG8A9XujaaMMxkyAhYO/H+q9Efg/Jqf74r0PpI4zj9sySqgFXM3ym
GDnmhTPfF8O+I1Rvt5zni/JRo6/HzQkTG7ghHX+e22twdJ+PMbJhm0fk7n4MbRJg
cYkuzQKBgQCY002bVTT0v/ND0zx5YCFo2OkN1pNw13+m2ar9omg6KHsmmIghsgUG
p8+4fnJus+0CYE/t+nuAD7JDfFcfYt53hqjCP2SgLMyAp5EVmW80v3l1E4ro8cqR
KX9lMTAwimMxF6ueY36g/k8/vKQuyG+uzsnBZtNAFmIGm1gGWjHBXA==
-----END RSA PRIVATE KEY-----
treehrt@hrt:~/mysqlc$

 

treehrt@hrt:~/mysqlc$ openssl req -new -key server.key -out server.csr

 

treehrt@hrt:~/mysqlc$ cat server.csr
-----BEGIN CERTIFICATE REQUEST-----
MIIC3TCCAcUCAQAwgZcxCzAJBgNVBAYTAlRXMRMwEQYDVQQIDApTb21lLVN0YXRl
MQ8wDQYDVQQHDAZLaW5tZW4xDTALBgNVBAoMBGttdnMxFDASBgNVBAsMC2luZm9y
bWF0aW9uMRswGQYDVQQDDBJ3d3cua212cy5rbS5lZHUudHcxIDAeBgkqhkiG9w0B
CQEWEXRyZWVocnRAZ21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAocpKIi6uVmkfOIWDcS3EQoB2eX8wQzU2pHK5PT5DptIIfk/cTE9mP+Cz
x2rG7waU/ufSwKCppCqawA4RmSNezxLVPym8VuNdNfrxwzq3TM5Xn28L4UkmT19u
RhXC8+NrUblHvdcbg4P6PRUPLSwkUcev59v217Xp7jDIRP5mmL5K4xQSX0CG7hb5
sofgLxaWF5grw7W+PEhShY9o3E2/Ibo+I53S0Up2GxN3BXkpp3zWJ19oCydqB4lI
AQhKjDUz7Yee3Pen6+FHE6GMCwRMYci4mr/b8K30RlJUXWeTNOST1Ptq0t/xTOOg
wucjaGbcFoI8zp+0mzWdRxLh6gP2nQIDAQABoAAwDQYJKoZIhvcNAQELBQADggEB
ADD8jLMZHANsQvKtu9Pwq/9fF8+LAD0W8BXO956AAONfs49wtZNxU6iC05Ugcpm/
ZmwraZGo0eUp3k58mxENPsCJNNENh2m0suLV8l1WZ5MCF+ErSBbS5ipaxfeMETsM
CIpj+WbxdRiglsuaQ5yw6zDh3f3+SutFicFfKgksWq3NOliJNQiC5/HHsw+N6RGU
wAM1Gn5wcZPDmWgaYE9uJvJ0Ix37WMqhINnnogAJL6TR4kb4nY2+VlPYASZInLqd
dEtzOfTWNiTj0Nzj8NmfQloQY1NN6Zee9c2/7wOtgskzeFtyc6IdLLmJLDP7rGxt
KY3cD9NaaRt6guv+t8P2vmE=
-----END CERTIFICATE REQUEST-----
treehrt@hrt:~/mysqlc$

 

20180613在GTK視窗顯示縮放到和視窗同樣大小的影像(gtk9b.c)
2018/06/13,23:17

(1)GTK視窗顯示縮放到和視窗同樣大小的影像(gtk9b.c)


treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk9b.c
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *image;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  image = gtk_image_new_from_file("map.png");

  gtk_container_add (GTK_CONTAINER (window), image);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit) , NULL);
  gtk_widget_set_size_request (window, 1024,768);

  GdkPixbuf *pixbuf =    gtk_image_get_pixbuf(GTK_IMAGE(image));
  if (pixbuf == NULL)
    {
        g_printerr("Failed to resize image\n");
        return 1;
    }
  int width, height;
  gtk_window_get_size(GTK_WINDOW(window), &width, &height);
  pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
  gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);

  gtk_widget_show_all (window);
  gtk_main();
  return 0;
}

 

(2)編譯並執行

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk9b.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out

alt

20180612在GTK視窗的Drawing Area顯示影像並偵測滑鼠按鍵位置(gtk9.c)
2018/06/12,22:27

(0)REF:

https://cairographics.org/tutorial/

http://zetcode.com/gfx/cairo/basicdrawing/

(1) 在GTK視窗的Drawing Area顯示影像並偵測滑鼠按鍵位置(gtk9.c)

treehrt@hrt:~/mysqlc$ cat gtk9.c
//http://zetcode.com/gfx/cairo/basicdrawing/
//resize :https://ubuntuforums.org/showthread.php?t=761973
#include <gtk/gtk.h>
#include <cairo.h>
#include <math.h>
int cx,cy;
GdkPixbuf *pix;

static gboolean on_window_draw (GtkWidget *da, GdkEvent *event, gpointer data)
{
    (void)event; (void)data;

    cairo_t *cr;
    cr = gdk_cairo_create (gtk_widget_get_window(da));
    gdk_cairo_set_source_pixbuf(cr, pix, 0, 0);
    cairo_paint(cr);
    cairo_destroy (cr);
    return TRUE;
}


static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
    if (event->button == 1) {
        g_print ("1:%f,%f\n", event->x, event->y);
    cx=event->x;
    cy=event->y;
        cairo_t *cr;

    cr = gdk_cairo_create (gtk_widget_get_window(widget));
 
    cairo_set_line_width(cr, 5);
    cairo_set_source_rgb(cr, 0, 1, 0);
    cairo_arc (cr, cx, cy, 10, 0, 2 * M_PI);

    cairo_stroke(cr);   
    cairo_destroy (cr);
    }

    if (event->button == 3) {
        g_print ("3:%f,%f\n", event->x, event->y);
    gtk_widget_queue_draw(widget);

    }
    return TRUE;
}


int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *canvas;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GError *err = NULL;
  pix = gdk_pixbuf_new_from_file("map.png", &err);
  if(err)
    {
        printf("Error : %s\n", err->message);
        g_error_free(err);
        return FALSE;
    }
  int w=gdk_pixbuf_get_width(pix);
  int h=gdk_pixbuf_get_height(pix);
 
  canvas = gtk_drawing_area_new ();
  gtk_window_set_default_size(GTK_WINDOW(window), 100, 100);
  gtk_widget_set_size_request (canvas, w,h);
  gtk_widget_set_size_request (window, w,h);

  gtk_container_add (GTK_CONTAINER (window), canvas);
  gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);

  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit) , NULL);
  g_signal_connect(window, "button-press-event", G_CALLBACK(clicked), NULL);
  g_signal_connect (canvas, "draw", (GCallback) on_window_draw, NULL);
  gtk_widget_set_app_paintable(canvas, TRUE);

  gtk_widget_show_all (window);
  gtk_main();
  return 0;
}

 

 

(2) 編譯執行

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk9.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &
[15] 5774
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ 3:347.677872,151.101303
3:347.677872,151.101303
3:347.677872,151.101303
3:347.677872,151.101303

 

20180612在GTK視窗顯示影像並偵測滑鼠按鍵位置(gtk8.c)
2018/06/12,20:51

(1) gtk8.c

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk8.c
#include <gtk/gtk.h>
static gboolean button_press_callback (GtkWidget      *event_box, GdkEventButton *event, gpointer        data)
{
    g_print ("%f,%f\n", event->x, event->y);
    return TRUE;
}

int main (int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
  GtkWidget *event_box;
  event_box = gtk_event_box_new ();
  gtk_container_add (GTK_CONTAINER (window), event_box);

  GtkWidget * im;
  im = gtk_image_new_from_file("map.png");
  gtk_container_add (GTK_CONTAINER (event_box), im);
  g_signal_connect (G_OBJECT(event_box), "button_press_event", G_CALLBACK (button_press_callback), im);

  gtk_window_set_title(GTK_WINDOW (window), "map");

  gtk_widget_show_all (window);
  gtk_main();
  return 0;
}

 

(2)編譯與執行


treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk8.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &
[12] 4470
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ 536.113159,156.131699
536.113159,156.131699
536.113159,156.131699
520.113159,137.131699
285.690460,133.012070
285.690460,133.012070
285.690460,133.012070
285.690460,133.012070
285.690460,133.012070

20180611在GTK視窗上建立二個Widget控制項(一個text,一個label或二個label)
2018/06/11,20:54

(1)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk6.c
//https://raw.githubusercontent.com/staalmannen/gqt/master/examples/textarea.c

#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *text;
  GtkWidget *label;

  gtk_init (&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


  GtkWidget *button_box;
  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  label = gtk_label_new("一首詩");
  gtk_container_add (GTK_CONTAINER (button_box), label);

  text = gtk_text_view_new();
  gtk_text_view_set_editable(GTK_TEXT_VIEW (text), TRUE);
  gtk_container_add (GTK_CONTAINER (button_box), text);

  GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (text));
  gtk_text_buffer_set_text(buf,  "會活就會活,會死就會死,一切活該到楣,也幸福快樂。", -1);

  gtk_window_set_default_size (GTK_WINDOW(window), 320, 160);

  gtk_window_set_title(GTK_WINDOW (window), "Text文字盒與Label標籤");

  gtk_widget_show_all (window);

  gtk_main();

  return 0;
}

(2)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk6.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &

 

(3)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk7.c
//REF: https://raw.githubusercontent.com/staalmannen/gqt/master/examples/label.c
//https://www.cc.gatech.edu/data_files/public/doc/gtk/tutorial/gtk_tut.html#toc4
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *label1;
  GtkWidget *label2;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
  GtkWidget *button_box;
  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  label1 = gtk_label_new("大悲無言");
  label2 = gtk_label_new("大智若愚");
  gtk_container_add(GTK_CONTAINER (button_box), label1);
  gtk_container_add(GTK_CONTAINER (button_box), label2);

  gtk_window_set_default_size (GTK_WINDOW(window), 320, 160);

  gtk_window_set_title(GTK_WINDOW (window), "Label標籤*2");

  gtk_widget_show_all (window);

  gtk_main();

  return 0;
}

(4)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk7.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &

 

20180610在ubuntu用c在mysql ilvssell資料庫建立資料表new_id_reg
2018/06/10,09:56

(1) t10.c

:

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

 mysql_query(con, "set names utf8");

 char st[]="CREATE TABLE new_id_reg(sta_no char(1),inday char(20) default '2018-08-08 08:08:08',custno char(10) default '818818',money_store int default 0, saleno char(10) default '-' ,remain int default 0,serial char(20) primary key,oldremain int default 0) ";
  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);

:

(2)

treehrt@treehrt-fire:~/mysqlc$ gcc t10.c `mysql_config --cflags --libs`
treehrt@treehrt-fire:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
DROP TABLE new_id_reg ok!
Prepare CREATE TABLE new_id_reg(sta_no char(1),inday char(20) default '2018-08-08 08:08:08',custno char(10) default '818818',money_store int default 0, saleno char(10) default '-' ,remain int default 0,serial char(20) primary key,oldremain int default 0)
Execute ok! 

 

20180609在ubuntu用c列出mysql ilvssell資料庫三個資料表的內容
2018/06/09,10:43

(1)列出mysql ilvssell資料庫三個資料表的內容 t9.c 程式碼摘述

:

void finish_with_error(MYSQL *con)
{
  fprintf(stderr, "%s\n", mysql_error(con));
  mysql_close(con);
  exit(1);       
}
const char * tab[] = {
    "new_cust",
    "new_goods",
    "new_factory"
};
#define n_tab (sizeof (tab) / sizeof (const char *))

:

  mysql_query(con, "set names utf8");
for (int i = 0; i < n_tab; i++) {
  printf ("\n%d: %s\n", i, tab[i]);

  char st[80];
//sprintf(st,"SELECT column_name from information_schema.columns where table_name = \"%s\" ",tab[i]);
  sprintf(st,"select * from %s",tab[i]);
  if (mysql_query(con, st)) finish_with_error(con);
  printf("SQL: [ %s ] Execute ok! \n\n", st);
  MYSQL_RES *result = mysql_store_result(con);
  if (result == NULL)
  {
      finish_with_error(con);
  }


  int num_fields = mysql_num_fields(result);

  MYSQL_FIELD *field;
  char *headers[num_fields];
  for(int k = 0; (field = mysql_fetch_field(result)); k++) {
    headers[k] = field->name;
    printf("%s, ",headers[k]);
   }
  printf("\n");

  MYSQL_ROW row;
  while ((row = mysql_fetch_row(result)))
  {
      for(int i = 0; i < num_fields; i++)
      {
          printf("%s, ", row[i] ? row[i] : "NULL");
      }
          printf("\n");
  }
  mysql_free_result(result);
 }

 

:

 

(2)編譯與執行:

treehrt@treehrt-fire:~/mysqlc$ gcc t9.c `mysql_config --cflags --libs`

treehrt@treehrt-fire:~/mysqlc$ ./a.out

0: new_cust
SQL: [ select * from new_cust ] Execute ok!

uid, remain, inyear, dept, grade, class, cardid, uname, pid, addr, tel, oldclass, sno, lostc, gen_code, in_use, cid4,
x, 1000, 107, x, 1, x, 512001, 王一志, x, x, x, x, x, 0, 0, 1, B301,

1: new_goods
SQL: [ select * from new_goods ] Execute ok!

gdsno, gdsname, spec, cost, price_in, price_special, price_sell, unit, stock_qty, fac_no, mem,
a001, 蕃茄, 個, 10, 10, 20, 20, 個, 200, 077, 金農行,

2: new_factory
SQL: [ select * from new_factory ] Execute ok!

facno, facname, simplify, phone1, phone2, fax, intername, interphone, master, facaddr, comaddr, lastdeal, rate, invoice, accountd, ps,
707, 金門農場, -, 082-333274, -, -, -, 082-333274, 吳小花, -, addr, 0, 0, 0, 123456, -,
treehrt@treehrt-fire:~/mysqlc$


 

20180608安裝並使用osCommerce
2018/06/08,13:26

(1) http://10.1.1.14/osc302/oscommerce看上週的 

 

20180608在ubuntu用c在mysql ilvssell資料庫新增一個資料表new_factory並新增一筆資料
2018/06/08,13:02

(1)

treehrt@hrt:~/mysqlc$ cat t7.c
:

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



 mysql_query(con, "set names utf8");

 char st[]="CREATE TABLE new_factory (facno char(20) primary key, facname char(30) default 'x', simplify char(10) default 'x',phone1 char(20) default '0823' , phone2 char(20) default '0', fax char(20) default '0', intername char(20) default '0', interphone char(20) default '0', master char(10) default '0' , facaddr char(40) default '0' , comaddr char(40) default '-' , lastdeal char(10) default '-', rate char(10) default '-' ,invoice char(20) default '-', accountd char(20) default '-', ps char(40) default '0')";

  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);

 

(2)

treehrt@hrt:~/mysqlc$ gcc t7.c `mysql_config --cflags --libs`

(3)

treehrt@hrt:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
DROP TABLE new_factory ok!
Prepare CREATE TABLE new_factory (facno char(20) primary key, facname char(30) default 'x', simplify char(10) default 'x',phone1 char(20) default '0823' , phone2 char(20) default '0', fax char(20) default '0', intername char(20) default '0', interphone char(20) default '0', master char(10) default '0' , facaddr char(40) default '0' , comaddr char(40) default '-' , lastdeal char(10) default '-', rate char(10) default '-' ,invoice char(20) default '-', accountd char(20) default '-', ps char(40) default '0')
Execute ok!

 

(4) 用mysql命令列指令列出new_factory資料表欄位結構:

mysql> desc new_factory;
+------------+----------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| facno      | char(20) | NO   | PRI | NULL    |       |
| facname    | char(30) | YES  |     | x       |       |
| simplify   | char(10) | YES  |     | x       |       |
| phone1     | char(20) | YES  |     | 0823    |       |
| phone2     | char(20) | YES  |     | 0       |       |
| fax        | char(20) | YES  |     | 0       |       |
| intername  | char(20) | YES  |     | 0       |       |
| interphone | char(20) | YES  |     | 0       |       |
| master     | char(10) | YES  |     | 0       |       |
| facaddr    | char(40) | YES  |     | 0       |       |
| comaddr    | char(40) | YES  |     | -       |       |
| lastdeal   | char(10) | YES  |     | -       |       |
| rate       | char(10) | YES  |     | -       |       |
| invoice    | char(20) | YES  |     | -       |       |
| accountd   | char(20) | YES  |     | -       |       |
| ps         | char(40) | YES  |     | 0       |       |
+------------+----------+------+-----+---------+-------+
16 rows in set (0.00 sec)

(5)  寫入一筆資料到new_factory資料表C程式碼t8.c 摘述:

 

 mysql_query(con, "set names utf8");

 char st[]="insert into new_factory (facno,facname,phone1,master, ps,accountd,invoice,rate,lastdeal,comaddr,facaddr, interphone,intername,fax,phone2,simplify) values ('707','金門農場','082-333274','吳小花','-',123456,'0','0','0','addr','-', '082-333274','-','-','-','-') ";

  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);

 

(6) 編譯並執行

treehrt@treehrt-fire:~/mysqlc$ gcc t8.c `mysql_config --cflags --libs`

treehrt@treehrt-fire:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
Prepare insert into new_factory (facno,facname,phone1,master, ps,accountd,invoice,rate,lastdeal,comaddr,facaddr, interphone,intername,fax,phone2,simplify) values ('707','金門農場','082-333274','吳小花','-',123456,'0','0','0','addr','-', '082-333274','-','-','-','-')
Execute ok! 

 

(7)

mysql> select * from new_factory;
+-------+--------------+----------+------------+--------+------+-----------+------------+-----------+---------+---------+----------+------+---------+----------+------+
| facno | facname      | simplify | phone1     | phone2 | fax  | intername | interphone | master    | facaddr | comaddr | lastdeal | rate | invoice | accountd | ps   |
+-------+--------------+----------+------------+--------+------+-----------+------------+-----------+---------+---------+----------+------+---------+----------+------+
| 707   | 金門農場     | -        | 082-333274 | -      | -    | -         | 082-333274 | 吳小花    | -       | addr    | 0        | 0    | 0       | 123456   | -    |
+-------+--------------+----------+------------+--------+------+-----------+------------+-----------+---------+---------+----------+------+---------+----------+------+
1 row in set (0.00 sec)

 

20180605在ubuntu用c在mysql ilvssell資料庫新增一個資料表new_goods並新增一筆資料
2018/06/05,13:09

(1)新增資料表new_goods  程式碼(t5)摘要

:

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

 mysql_query(con, "set names utf8");

 char st[]="CREATE TABLE new_goods (gdsno char(20) primary key, gdsname char(30) default 'x', spec char(10) default '個',cost float default 0 ,price_in float default 0, price_special float default 0, price_sell float default 0, unit char(10) default '個' , stock_qty int default 0, fac_no char(20) default '0', mem varchar(80) default 'none' )";

  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);

 

(2)編譯並執行:

treehrt@hrt:~/mysqlc$ gcc t5.c `mysql_config --cflags --libs`

treehrt@hrt:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
Prepare CREATE TABLE new_goods (gdsno char(20) primary key, gdsname char(30) default 'x', spec char(10) default '個',cost float default 0 ,price_in float default 0, price_special float default 0, price_sell float default 0, unit char(10) default '個' , stock_qty int default 0, fac_no char(20) default '0', mem varchar(80) default 'none' )
Execute ok!  CREATE TABLE new_goods (gdsno char(20) primary key, gdsname char(30) default 'x', spec char(10) default '個',cost float default 0 ,price_in float default 0, price_special float default 0, price_sell float default 0, unit char(10) default '個' , stock_qty int default 0, fac_no char(20) default '0', mem varchar(80) default 'none' )

 

(3)在mysql命令列查看結果:

mysql> use ilvssell;
Database changed


mysql> desc new_goods;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| gdsno         | char(20)    | NO   | PRI | NULL    |       |
| gdsname       | char(30)    | YES  |     | x       |       |
| spec          | char(10)    | YES  |     | 個      |       |
| cost          | float       | YES  |     | 0       |       |
| price_in      | float       | YES  |     | 0       |       |
| price_special | float       | YES  |     | 0       |       |
| price_sell    | float       | YES  |     | 0       |       |
| unit          | char(10)    | YES  |     | 個      |       |
| stock_qty     | int(11)     | YES  |     | 0       |       |
| fac_no        | char(20)    | YES  |     | 0       |       |
| mem           | varchar(80) | YES  |     | none    |       |
+---------------+-------------+------+-----+---------+-------+
11 rows in set (0.00 sec)

(4)新增一筆資料到new_goods  程式碼(t6)摘要

mysql_query(con, "set names utf8");

char st[]="INSERT INTO new_goods (GDSNO,GDSNAME,SPEC, COST,PRICE_in,PRICE_SPECIAL,PRICE_SELL, UNIT,STOCK_QTY,FAC_NO,MEM) VALUES ('a001','蕃茄','個', 10,10,20,20,'個',200,'077','金農行') ";
  if (mysql_query(con, st))
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }

(5)編譯並執行

eehrt@hrt:~/mysqlc$ gcc t6.c `mysql_config --cflags --libs`
treehrt@hrt:~/mysqlc$ ./a.out
MySQL client version: 5.7.22
Prepare INSERT INTO new_goods (GDSNO,GDSNAME,SPEC, COST,PRICE_in,PRICE_SPECIAL,PRICE_SELL, UNIT,STOCK_QTY,FAC_NO,MEM) VALUES ('a001','蕃茄','個', 10,10,20,20,'個',200,'077','金農行')
Execute ok! 

(6)查看

treehrt@hrt:~/mysqlc$ mysql -p -uroot

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> select * from new_goods;
+-------+---------+------+------+----------+---------------+------------+------+-----------+--------+-----------+
| gdsno | gdsname | spec | cost | price_in | price_special | price_sell | unit | stock_qty | fac_no | mem       |
+-------+---------+------+------+----------+---------------+------------+------+-----------+--------+-----------+
| a001  | 蕃茄    | 個   |   10 |       10 |            20 |         20 | 個   |       200 | 077    | 金農行    |
+-------+---------+------+------+----------+---------------+------------+------+-----------+--------+-----------+
1 row in set (0.00 sec)

 

20180602在ubuntu裝gtk-3-examples並執行 gtk3-demo 、gtk3-icon-browser及gtk3-widget-factory
2018/06/02,20:30

(1)treehrt@treehrt-fire:~$ sudo apt-get install gtk-3-examples
:

下列【新】套件將會被安裝:
  gtk-3-examples
升級 0 個,新安裝 1 個,移除 0 個,有 187 個未被升級。
需要下載 565 kB 的套件檔。
此操作完成之後,會多佔用 3,061 kB 的磁碟空間。
下載:1 http://tw.archive.ubuntu.com/ubuntu xenial-updates/main amd64 gtk-3-examples amd64 3.18.9-1ubuntu3.3 [565 kB]
取得 565 kB 用了 1秒 (366 kB/s)       
選取了原先未選的套件 gtk-3-examples。
(讀取資料庫 ... 目前共安裝了 424525 個檔案和目錄。)
準備解開 .../gtk-3-examples_3.18.9-1ubuntu3.3_amd64.deb ...
解開 gtk-3-examples (3.18.9-1ubuntu3.3) 中...
Processing triggers for libglib2.0-0:amd64 (2.48.2-0ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
設定 gtk-3-examples (3.18.9-1ubuntu3.3) ...

(2)treehrt@treehrt-fire:~$ gtk3-demo &

(3)treehrt@treehrt-fire:~/mysqlc$ gtk3-icon-browser &

(4)treehrt@treehrt-fire:~/mysqlc$ gtk3-widget-factory &


20180602在ubuntu裝glade GUI 介面編輯程式並編譯執行gtk5.c程式
2018/06/02,14:29

treehrt@treehrt-fire:~/mysqlc$ sudo apt-get install glade

下列的額外套件將被安裝:
  libgladeui-2-6 libgladeui-common
下列【新】套件將會被安裝:
  glade libgladeui-2-6 libgladeui-common
升級 0 個,新安裝 3 個,移除 0 個,有 187 個未被升級。
需要下載 810 kB 的套件檔。
此操作完成之後,會多佔用 7,685 kB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] y
下載:1 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 libgladeui-common all 3.18.3-1 [97.4 kB]
下載:2 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 libgladeui-2-6 amd64 3.18.3-1 [480 kB]
下載:3 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 glade amd64 3.18.3-1 [233 kB]
取得 810 kB 用了 1秒 (577 kB/s)
選取了原先未選的套件 libgladeui-common。
(讀取資料庫 ... 目前共安裝了 424034 個檔案和目錄。)
準備解開 .../libgladeui-common_3.18.3-1_all.deb ...
解開 libgladeui-common (3.18.3-1) 中...
選取了原先未選的套件 libgladeui-2-6。
準備解開 .../libgladeui-2-6_3.18.3-1_amd64.deb ...
解開 libgladeui-2-6 (3.18.3-1) 中...
選取了原先未選的套件 glade。
準備解開 .../glade_3.18.3-1_amd64.deb ...
解開 glade (3.18.3-1) 中...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
設定 libgladeui-common (3.18.3-1) ...
設定 libgladeui-2-6 (3.18.3-1) ...
設定 glade (3.18.3-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...

(2)用glade製作產生如下檔(window_main.glade)

treehrt@treehrt-fire:~/mysqlc$ cat window_main.glade
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkWindow" id="window_main">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">樣版視窗</property>
    <property name="default_width">634</property>
    <property name="default_height">480</property>
    <signal name="destroy" handler="on_window_main_destroy" swapped="no"/>
    <child>
      <object class="GtkImage" id="image1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="pixbuf">Firefox_wallpaper.png</property>
      </object>
    </child>
  </object>
</interface>
treehrt@treehrt-fire:~/mysqlc$

 
treehrt@treehrt-fire:~/mysqlc$

(3)用vi編寫如下程式(gtk5.c)

treehrt@treehrt-fire:~/mysqlc$ cat gtk5.c
// REF: https://prognotes.net/2015/06/gtk-3-c-program-using-glade-3/
#include <gtk/gtk.h>

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


    GtkBuilder      *builder;
    GtkWidget       *window;
 
    gtk_init(&argc, &argv);
 
    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "window_main.glade", NULL);
 
    window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
    gtk_builder_connect_signals(builder, NULL);
 
    g_object_unref(builder);
 
    gtk_widget_show(window);               
    gtk_main();
 
    return 0;
}

void on_window_main_destroy()
{
    gtk_main_quit();
}

 

 

(4)編譯並執行成功

treehrt@treehrt-fire:~/mysqlc$ gcc gtk5.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic

(5)REF:

https://prognotes.net/2015/06/gtk-3-c-program-using-glade-3/

 

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType