/ Check-in [58c0c74c]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add the "filetype()" SQL function for interpreting file modes to the fileio.c extension.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | archive-improvements
Files: files | file ages | folders
SHA3-256: 58c0c74c407d93f48930a4964b6cc48f008b522d193a62a559de0e6a319a8bd0
User & Date: drh 2018-01-10 15:53:06
Context
2018-01-10
16:50
Implement the ".ar --create" command using a single "REPLACE INTO sqlar SELECT ... FROM fsdir();" statement. Add the shell_putsnl() SQL function for providing --verbose output. check-in: 28ab9304 user: drh tags: archive-improvements
15:53
Add the "filetype()" SQL function for interpreting file modes to the fileio.c extension. check-in: 58c0c74c user: drh tags: archive-improvements
15:17
The ".ar" command deduces whether or not the target file is a ZIP or SQLAR and does the appropropriate thing. The "-z" option is omitted. The "--append" option is added to open auxiliary databases using apndvfs. check-in: 430d1a7d user: drh tags: archive-improvements
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/misc/fileio.c.

352
353
354
355
356
357
358
























359
360
361
362
363
364
365
...
764
765
766
767
768
769
770




771
772
773
774
775
    }else if( S_ISDIR(mode) ){
      ctxErrorMsg(context, "failed to create directory: %s", zFile);
    }else{
      ctxErrorMsg(context, "failed to write file: %s", zFile);
    }
  }
}

























#ifndef SQLITE_OMIT_VIRTUALTABLE

/* 
** Cursor type for recursively iterating through a directory structure.
*/
typedef struct fsdir_cursor fsdir_cursor;
................................................................................
  (void)pzErrMsg;  /* Unused parameter */
  rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
                               readfileFunc, 0, 0);
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
                                 writefileFunc, 0, 0);
  }




  if( rc==SQLITE_OK ){
    rc = fsdirRegister(db);
  }
  return rc;
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>





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
...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
    }else if( S_ISDIR(mode) ){
      ctxErrorMsg(context, "failed to create directory: %s", zFile);
    }else{
      ctxErrorMsg(context, "failed to write file: %s", zFile);
    }
  }
}

/*
** SQL function:   filetype(MODE)
**
** Based on the integer mode, return one of "file", "directory", or "symlink".
*/
static void fileTypeFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const char *zMode;
  int iMode = sqlite3_value_int(argv[0]);
  if( S_ISLNK(iMode) ){
    zMode = "symlink";
  }else if( S_ISREG(iMode) ){
    zMode = "file";
  }else if( S_ISDIR(iMode) ){
    zMode = "directory";
  }else{
    zMode = "unknown";
  }
  sqlite3_result_text(context, zMode, -1, SQLITE_STATIC);
}

#ifndef SQLITE_OMIT_VIRTUALTABLE

/* 
** Cursor type for recursively iterating through a directory structure.
*/
typedef struct fsdir_cursor fsdir_cursor;
................................................................................
  (void)pzErrMsg;  /* Unused parameter */
  rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
                               readfileFunc, 0, 0);
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_function(db, "writefile", -1, SQLITE_UTF8, 0,
                                 writefileFunc, 0, 0);
  }
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_function(db, "fileType", 1, SQLITE_UTF8, 0,
                                 fileTypeFunc, 0, 0);
  }
  if( rc==SQLITE_OK ){
    rc = fsdirRegister(db);
  }
  return rc;
}