MariaDB - Consulta en MariaDB

 
Vista:

Consulta en MariaDB

Publicado por Matias (1 intervención) el 10/07/2015 06:24:56
Buenas, mi consulta es como obtener los nombres de usuario que tengan la cadena 'nh' én su
nombre
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Consulta en MariaDB

Publicado por Laincha (1 intervención) el 03/06/2022 18:27:18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/*
http://www.cs.wichita.edu/~chang/lecture/cs742/program/how-mysql-c-api.html
http://epweb2.ph.bham.ac.uk/user/hillier/course3cpp/howto/
https://gcc.gnu.org/onlinedocs/cpp/Macros.html
https://www.programiz.com/c-programming/c-preprocessor-macros
https://www.cs.yale.edu/homes/aspnes/pinewiki/C(2f)Macros.html
http://web.cse.ohio-state.edu/~sivilotti.1/teaching/3903.recent/lectures/
*/
 
/*-------CreateDB.c---------*/
 
/*
MYSQL *mysql_init(MYSQL *mysql)
MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char
*user, const char *passwd, const char *db,
 unsigned int port, const char *unix_socket, unsigned int client_flag)
char *mysql_error(MYSQL *mysql)
int mysql_create_db(MYSQL *mysql, const char *db)
*/
 
#ifdef WIN32
  #include <windows.h>
  #include <winsock.h>
  #pragma warning (disable: 4514 4786)
  #pragma warning( push, 3 )
#endif
 
#include <stdio.h>
#include "mysql.h"
 
int main(int argc, char **argv) {
 
     MYSQL connHand;
     char *server   = "localhost";   /* direccion del servidor 127.0.0.1, localhost o direccion ip     */
     char *user     = "root";        /* usuario para consultar la base de datos                        */
     char *password = "";            /* contraseña para el usuario en cuestion                         */
     char *database = "dbcenso";     /* nombre de la base de datos a consultar                         */
 
     printf("\n\n\tCopyright Lai Anei Kiska\n\t\t mongotaitang.com.ar/lanc/");
     printf("\n\t\laian890@gmail.com \n\t\tPhone: (011) 4365-8496\n");
     if ( mysql_init(&connHand ) == NULL ) {
          printf("\nFailed to initate MySQL connection");
          exit(1);
     }
     /*
      *
      * now you can call any MySQL API function you like
      *
      */
     if (!mysql_real_connect(&connHand, server, user, password, NULL,0,NULL,0)) {
          printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&connHand));
          exit(1);
     }
 
     /*success*/
     if ( mysql_create_db(&connHand, "DhakaStockExchangeGame" )==0)
          printf( "Database Created\n");
     else
          printf( "Failed to create new database.  Error: %s\n", mysql_error(&connHand));
 
     mysql_close(&connHand);
}
 
 
 
/*-------DeleteDB.c---------*/
 
/*
MYSQL *mysql_init(MYSQL *mysql)
MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char
*user, const char *passwd, const char *db,
 unsigned int port, const char *unix_socket, unsigned int client_flag)
char *mysql_error(MYSQL *mysql)
int mysql_drop_db(MYSQL *mysql, const char *db)
*/
 
#ifdef WIN32
  #include <windows.h>
  #include <winsock.h>
  #pragma warning (disable: 4514 4786)
  #pragma warning( push, 3 )
#endif
 
#include <stdio.h>
#include "mysql.h"
#ifndef WIN32
   #include <unistd.h>
#endif
 
int main(int argc, char **argv) {
 
     MYSQL mysql;
 
     printf("\n\n\tCopyright Aftab Jahan Subedar\n\t\t mongotaitang.com.ar/lanc/");
     printf("\n\t\laian890@gmail.com \n\t\tPhone:+88027519050\n");
     if (mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         exit(1);
     }
     /*now you can call any MySQL API function you like*/
     if (!mysql_real_connect(&mysql,"subedartech.sytes.net","jahan","shoja_passwd",NULL,0,NULL,0))
     {
          printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
          exit(1);
     }
     if (mysql_drop_db(&mysql, "dbcenso" )==0)   /*success*/
          printf( "Database Deleted\n");
     else
          printf( "Failed to delete database.  Error: %s\n", mysql_error(&mysql));
     mysql_close(&mysql);
}
 
 
 
Creating Tables
 
/*-------CreateTable.c---------*/
 
 
#include <stdio.h>
#include <string.h>
#include "mysql.h"
 
 
 
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t\t mongotaitang.com.ar/lanc/");
    printf("\n\t\laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
 
    strcat(ccSQL,"CREATE TABLE TDOCUMENTOS ( ");
    strcat(ccSQL,"DOC_TIPO     SMALLINT      NOT NULL, ");
    strcat(ccSQL,"DOC_FECUPTE  VARCHAR(060)  NOT NULL, ");
    strcat(ccSQL,"DOC_DESCRIP  VARCHAR(060)  NOT NULL, ");
    strcat(ccSQL,"DOC_ABREVIA  CHAR   (006)  NOT NULL, ");
    strcat(ccSQL,"PRIMARY KEY( DOC_TIPO ) )");
 
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "Table Created\n");
    else
         printf( "Failed to create table: Error: %s\n",
    mysql_error(&mysql));
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------
 */
 
 
 
 
 
 
 
Editing
Tables
 
/*-------EditTable.c---------*/
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/lanc/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"Alter TABLE TDOCUMENTOS ");
    strcat(ccSQL,"MODIFY DOC_FECUPTE  VARCHAR(008)  NOT NULL");
 
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "Table Altered\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 */
 
 
 
 
 
 
 
 
Deleting
Tables
 
/*-------DeleteTable.c---------*/
 
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"DROP TABLE TDOCUMENTOS ");
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "Tabla Eliminada\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 */
 
 
 
 
 
 
 
Creating
Index
 
/*-------CreateIndex.c---------*/
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )");
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "Indice creado en forma satisfactoria\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 |   "CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )"
 |-----------------------------------------------------------------
 */
 
 
 
 
 
Deleting
Index
 
/*-------DeleteIndex.c---------*/
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"DROP INDEX DOC_TIPOS ON TDOCUMENTOS ");
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "Indice eliminado en forma satisfactoria\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 |   "CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )"
 |-----------------------------------------------------------------
 |   "DROP INDEX DOC_TIPOS ON TDOCUMENTOS"
 |-----------------------------------------------------------------
 */
 
 
 
 
 
 
 
 
/*
 *======================================================================
 *
 *  Data Manipulation Examples
 *  **************************
 *
 *======================================================================
 */
 
Adding records to table
 
/*-------AddRecords.c---------*/
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"INSERT INTO TDOCUMENTOS VALUES ( 001,'20190720','DOCUMENTOS NACIONAL DE IDENTIDAD','D.N.I.')");
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "INSERT OK!\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 |   "CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )"
 |-----------------------------------------------------------------
 |   "DROP INDEX DOC_TIPOS ON TDOCUMENTOS"
 |-----------------------------------------------------------------
 |   "INSERT INTO TDOCUMENTOS  VALUES ( 001,'20190720','DOCUMENTOS NACIONAL DE IDENTIDAD','D.N.I.'"
 |-----------------------------------------------------------------
 */
delete all record
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\tLai Anei Kiska \n\t mongotaitang.com.ar/");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"DELETE FROM TDOCUMENTOS");
    printf( "%s\n", ccSQL );
 
    if ( mysql_exec_sql(&mysql,ccSQL )==0)
         printf( "DELETE OK!\n");
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 |   "CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )"
 |-----------------------------------------------------------------
 |   "DROP INDEX DOC_TIPOS ON TDOCUMENTOS"
 |-----------------------------------------------------------------
 |   "INSERT INTO TDOCUMENTOS  VALUES ( 001,'20190720','DOCUMENTOS NACIONAL DE IDENTIDAD','D.N.I.'"
 |-----------------------------------------------------------------
 */
finding records from table
 
/*-------FindRecordsStatic.c---------*/
 
/*========================================================================*/
#include <stdio.h>
#include <string.h>
#include "mysql.h"
/*========================================================================*/
 
int mysql_exec_sql(MYSQL *mysql,const char *create_definition) {
    return mysql_real_query(mysql,create_definition,strlen(create_definition));
}
 
int main(int argc, char **argv) {
 
    MYSQL mysql;
    MYSQL_RES *result;
    MYSQL_ROW row;
 
    unsigned int num_fields;
    unsigned int i;
 
    char ccSQL[1000]={0x00};
 
    printf("\n\t Lai Anei Kiska \n\t mongotaitang.com.ar");
    printf("\n\t\ laian890@gmail.com\n");
 
    if ( mysql_init(&mysql)==NULL) {
         printf("\nFailed to initate MySQL connection");
         return(1);
    }
 
    if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) {
 
         printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
         return(1);
    }
 
    if(mysql_select_db(&mysql,"test")==0)
        printf( "Database Selected\n");
    else
        printf( "Failed to connect to Database: Error: %s\n",
    mysql_error(&mysql));
 
    strcat(ccSQL,"SELECT DOC_TIPO, DOC_DESCRIP, DOC_ABREVIA FROM TDOCUMENTOS");
    printf( "%s\n", ccSQL );
 
    if (mysql_exec_sql(&mysql,ccSQL)==0) {
        printf( "%ld Record Found\n",(long) mysql_affected_rows(&mysql));
        result = mysql_store_result(&mysql);
        if (result) {
            num_fields = mysql_num_fields(result);
 
            unsigned long *lengths = mysql_fetch_lengths(result);
            while ((row = mysql_fetch_row(result))) {
 
               for (i = 0; i < num_fields; i++) {
                    printf("[%.*s] ", (int)lengths[i], row[i] ? row[i] : "NULL");
                }
               printf("\n");
            }
            mysql_free_result(result) ;
         } else  {
            if(mysql_field_count(&mysql) > 0) {
                printf( "Error getting records: %s\n", mysql_error(&mysql));
            }
         }
    }
 
    else
         printf( "Failed to connect to edit table: Error: %s\n", mysql_error(&mysql));
 
    mysql_close(&mysql);
}
 
/*
 |-----------------------------------------------------------------
 |   "CREATE TABLE TDOCUMENTOS ( "
 |   "DOC_TIPO        SMALLINT      NOT NULL, "
 |   "DOC_FECUPTE     VARCHAR(060)  NOT NULL, "
 |   "DOC_DESCRIP     VARCHAR(060)  NOT NULL, "
 |   "DOC_ABREVIA     CHAR   (006)  NOT NULL, "
 |   "PRIMARY KEY( DOC_TIPO ) )"
 |-----------------------------------------------------------------
 |   "Alter TABLE TDOCUMENTOS "
 |   "MODIFY DOC_FECUPTE     VARCHAR(008)  NOT NULL"
 |-----------------------------------------------------------------
 |   "DROP TABLE TDOCUMENTOS "
 |-----------------------------------------------------------------
 |   "CREATE INDEX DOC_TIPOS ON TDOCUMENTOS( DOC_TIPO )"
 |-----------------------------------------------------------------
 |   "DROP INDEX DOC_TIPOS ON TDOCUMENTOS"
 |-----------------------------------------------------------------
 |   "INSERT INTO TDOCUMENTOS  VALUES ( 001,'20190720','DOCUMENTOS NACIONAL DE IDENTIDAD','D.N.I.'"
 |-----------------------------------------------------------------
 |   "SELECT DOC_TIPO, DOC_DESCRIP, DOC_ABREVIA FROM TDOCUMENTOS"
 |-----------------------------------------------------------------
 */
 
 
 
 
 
 
CGI Examples
 
JPEG OUTPUT FROM JPEG FIELD
 
/*********************************************************************
 g++ -o /usr/local/www/cgi-bin/jpeg_mysql.cgi  jpeg_mysql_cgi_test.c
-I/usr/local/include -L/usr/local/lib/mysql -lc -lmysqlclient
 *********************************************************************
 */
#include <stdio.h>
/*#include <sys/types.h>
#include <sys/stat.h> fstat
#include <sys/uio.h>
#include <string.h>*/
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>/*get env*/
#include <mysql/mysql.h>
#include <syslog.h>/*syslog*/
#include <stdarg.h>
#define HTTP_STR "HTTP/1.1 200 OK\n"
#define HTTP_SERVER  "Server: Subedar Technologies\n"
#define HTTP_CONTENT "Content-type: image/jpeg\n\n"
int main(int argc, char *argv[])
{
        char *query="SELECT JPEG FROM Snaps ORDER BY ID DESC LIMIT
1";
    MYSQL mysql;
        mysql_init(&mysql);
        if(!mysql_real_connect
(&mysql,"","your_login_name","your_mysql_password","your_database",0,NULL,0))
        {
syslog(LOG_CONS,"%s->%s","MySQL Connect
Error:",mysql_error(&mysql));
                         mysql_close(&mysql);
                         exit(0);
        }
        if(mysql_query(&mysql,query))
        {
syslog(LOG_CONS,"%s->%s","MySQL Query
Eorror:",mysql_error(&mysql));
                         mysql_close(&mysql);
                         exit(0);
        }
        MYSQL_RES *result;
        result = mysql_use_result(&mysql);
        if (result)  // there are rows
        {
                /* retrieve rows, then call mysql_free_result(result)*/
                MYSQL_ROW row;
                if((row = mysql_fetch_row(result)))
                {
                        unsigned long *lengths =
mysql_fetch_lengths(result);
                        if(lengths[0] > 0)
                        {
                                write(STDOUT_FILENO, HTTP_CONTENT,
strlen(HTTP_CONTENT));
                                write(STDOUT_FILENO,row[0],lengths[0]);
                        }
                }
                mysql_free_result(result);
        }
        mysql_close(&mysql);
        exit(0);
}
Z:\Paradox\Programs\pdxwin32.exe -O c:\Ozoia78\L400.cfg -P C:\TEMP -W c:\Ozoia78\Local\  Gamanu.fdl -Q
GRANT ALL PRIVILEGES ON ATLAS.* TO '/' "
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Consulta en MariaDB

Publicado por laianie (1 intervención) el 03/06/2022 18:29:38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@Echo Off
Rem  Compile options file directory path.
Set  LD_LIBRARY_PATH=C:\MinGW\lib\;C:\MinGW\local\lib\;c:\Mariadb\lib\
Set  DIRLIB=C:\Mariadb\lib
 
Set  INCMGW=C:\MinGW\Include
Set  INCSQL=C:\Mariadb\include\mysql
 
Rem  Win32 (MinGW) dynamically loaded DLL search path.
Set  PATH=C:\MinGW;C:\MinGW\bin;C:\MinGW\local\bin;c:\Mariadb\bin;c:\Mariadb\lib;%PATH%
 
Rem  Temporary files directory path.
Set  TEMP=%TEMP%
 
Set CODC=%1.c
Set CODO=%1.o
Set CODE=%1.exe
 
Rem C:\MinGW\bin\gcc test.c -o test -Wl,-v
Rem C:\MinGW\bin\gcc -c %CODC% -o %CODO%
@Echo On
 
Rem C:\MinGW\bin\gcc %CODC% -o %CODE%  --verbose
echo ===================================================================
echo -I%INCMGW% -I%INCSQL%
echo ===================================================================
rem C:\MinGW\bin\gcc -I%INCMGW% -I%INCSQL%  %CODC% -o %CODE%  -lpdcurses -lpdcurses_dll  --verbose
C:\MinGW\bin\gcc -I%INCMGW% -I%INCSQL% -L%DIRLIB% -L%LD_LIBRARY_PATH% %CODC% -o %CODE%  -lmysql --verbose
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar