Advertisement
obernardovieira

SQLite Tutorial (codigo exemplo)

Sep 22nd, 2013
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.03 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. main()
  4. {
  5.     print("\n----------------------------------");
  6.     print(" Blank Gamemode by your name here");
  7.     print("----------------------------------\n");
  8. }
  9.  
  10. new DB:basedados;
  11.  
  12. public OnGameModeInit()
  13. {
  14.  
  15.     basedados = db_open("base_dados");
  16.  
  17.  
  18.     //new DBResult: resultado;
  19.    
  20.     /*db_free_result(db_query(basedados, "CREATE TABLE IF NOT EXISTS `jogadores`(`nome`,`idade`)"));
  21.    
  22.     db_free_result(db_query(basedados,"DELETE FROM `jogadores`"));
  23.    
  24.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Bernardo','18')"));
  25.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Jose','18')"));
  26.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Andre','17')"));
  27.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Joao','17')"));
  28.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Pedro','19')"));
  29.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Joana','14')"));
  30.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Maria','18')"));*/
  31.    
  32.    
  33.    
  34.     db_free_result(db_query(basedados,"DROP TABLE `players`"));
  35.    
  36.     db_free_result(db_query(basedados, "CREATE TABLE IF NOT EXISTS `jogadores`(`nome`,`idade` DEFAULT '15')"));
  37.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`,`idade`) VALUES('Bernardo','18')"));
  38.     db_free_result(db_query(basedados,"INSERT INTO `jogadores`(`nome`) VALUES('Joao')"));
  39.    
  40.    
  41.    
  42.    
  43.     /*db_free_result(db_query(basedados,"DELETE FROM `jogadores` WHERE `idade`='18'"));
  44.    
  45.     resultado = db_query(basedados,"SELECT * FROM `jogadores` WHERE `idade`='17'");
  46.    
  47.     new numeroresultados;
  48.     numeroresultados = db_num_rows(resultado);
  49.  
  50.     new nome[24],idade;
  51.    
  52.     for(new r;r!=numeroresultados;r++) {
  53.    
  54.         db_get_field(resultado, 1, nome, 24);
  55.         db_get_field_assoc(resultado, "idade", nome, 24);
  56.         idade = strval(nome);
  57.  
  58.  
  59.         db_get_field_assoc(resultado, "nome", nome, 24);
  60.         db_next_row(resultado);
  61.  
  62.         printf("nome : %s - idade : %d",nome,idade);
  63.        
  64.     }*/
  65.    
  66.    
  67.    
  68.    
  69.     /*new numeroresultados;
  70.     numeroresultados = db_num_rows(resultado);
  71.    
  72.     new nome[24],idade;
  73.    
  74.     db_field_name(resultado, 1, nome, 15);
  75.     printf("nome field : %s\n",nome);
  76.    
  77.     printf("num rows :%d - num field : %d\n",numeroresultados,db_num_fields(resultado));
  78.    
  79.     for(new r;r!=numeroresultados;r++) {
  80.    
  81.         //db_get_field(resultado, 1, nome, 24);
  82.         db_get_field_assoc(resultado, "idade", nome, 24);
  83.         idade = strval(nome);
  84.        
  85.         //db_get_field(resultado, 0, nome, 24);
  86.        
  87.         db_get_field_assoc(resultado, "nome", nome, 24);
  88.         db_next_row(resultado);
  89.        
  90.         printf("nome : %s - idade : %d",nome,idade);
  91.        
  92.        
  93.    
  94.     }*/
  95.    
  96.     //db_free_result(resultado);
  97.    
  98.  
  99.  
  100.     // Don't use these lines if it's a filterscript
  101.     SetGameModeText("Blank Script");
  102.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  103.    
  104.     db_close(basedados);
  105.    
  106.     return 1;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement