SQLite

Check-in [c906739f0c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tab-completion now also works using readline/editline.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | experimental-namelist
Files: files | file ages | folders
SHA3-256: c906739f0c1046b57a8c6d4aa32dbfbb4c59a8d94eb87243bf5135c665492129
User & Date: drh 2017-07-06 20:08:17.868
Context
2017-07-06
22:40
Always load the schema before starting tab-completion. (check-in: 907fd3aab6 user: drh tags: experimental-namelist)
20:08
Tab-completion now also works using readline/editline. (check-in: c906739f0c user: drh tags: experimental-namelist)
19:26
Use the sqlite3_namelist() interface to implement simple tab-completion using linenoise. (check-in: 5cc7b0e2ca user: drh tags: experimental-namelist)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/shell.c.
3595
3596
3597
3598
3599
3600
3601



























3602
3603
3604
3605
3606
3607
3608
3609
                            sha3QueryFunc, 0, 0);
    sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0,
                            shellAddSchemaName, 0, 0);
                            
  }
}




























#ifdef HAVE_LINENOISE
/*
** Linenoise completion callback
*/
static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
  int nLine = (int)strlen(zLine);
  int i, n, iStart;
  char **az;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
                            sha3QueryFunc, 0, 0);
    sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0,
                            shellAddSchemaName, 0, 0);
                            
  }
}

#if HAVE_READLINE || HAVE_EDITLINE
/*
** Readline completion callbacks
*/
static char *readline_completion_generator(const char *text, int state){
  static char **azCompletions = 0;
  static int iCompletion = 0;
  char *zRet;
  if( state==0 ){
    sqlite3_free(azCompletions);
    azCompletions = sqlite3_namelist(globalDb, text, -1, 0);
    iCompletion = 0;
  }
  zRet = azCompletions[iCompletion++];
  if( zRet==0 ){
    sqlite3_free(azCompletions);
    azCompletions = 0;
  }else{
    zRet = strdup(zRet);
  }
  return zRet;
}
static char **readline_completion(const char *zText, int iStart, int iEnd){
  rl_attempted_completion_over = 1;
  return rl_completion_matches(zText, readline_completion_generator);
}

#elif HAVE_LINENOISE
/*
** Linenoise completion callback
*/
static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
  int nLine = (int)strlen(zLine);
  int i, n, iStart;
  char **az;
7661
7662
7663
7664
7665
7666
7667


7668
7669
7670
7671
7672
7673
7674
7675
      if( zHome ){
        nHistory = strlen30(zHome) + 20;
        if( (zHistory = malloc(nHistory))!=0 ){
          sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
        }
      }
      if( zHistory ){ shell_read_history(zHistory); }


#ifdef HAVE_LINENOISE
      linenoiseSetCompletionCallback(linenoise_completion);
#endif
      rc = process_input(&data, 0);
      if( zHistory ){
        shell_stifle_history(100);
        shell_write_history(zHistory);
        free(zHistory);







>
>
|







7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
      if( zHome ){
        nHistory = strlen30(zHome) + 20;
        if( (zHistory = malloc(nHistory))!=0 ){
          sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
        }
      }
      if( zHistory ){ shell_read_history(zHistory); }
#if HAVE_READLINE || HAVE_EDITLINE
      rl_attempted_completion_function = readline_completion;
#elif HAVE_LINENOISE
      linenoiseSetCompletionCallback(linenoise_completion);
#endif
      rc = process_input(&data, 0);
      if( zHistory ){
        shell_stifle_history(100);
        shell_write_history(zHistory);
        free(zHistory);