SQLite Forum

shell's .load is pathSep picky
Login
I see that the load_extension() function is failing not because backslashes in the path trip up loading the DLL but because they confound derivation of the entry point name from that path.

In the sqlite3.exe shell of any recent vintage, this succeeds:
```
  sqlite> select load_extension('c:\Bin\natsort', 'sqlite3_natsort_init');
```
and, because the shell was run from c:\\Bin, this succeeds:
```
  sqlite> select load_extension('natsort');
```
whereas this fails:
```
  sqlite> select load_extension('c:\Bin\natsort');
  Error: The specified procedure could not be found.
```
The complaint provides a decent clue as well.
Proof takes the form of replacing this code in sqlite3LoadExtension()
```
    memcpy(zAltEntry, "sqlite3_", 8);
    for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
```
with this code (at line 88 of the function):
```
    memcpy(zAltEntry, "sqlite3_", 8);
    for(iFile=ncFile-1; iFile>=0 &&
 #if SQLITE_OS_WIN
	  zFile[iFile]!='\\' &&
 #endif
	  zFile[iFile]!='/'; iFile--){}
```

To wit, with headers emitted regardless of result row count:

```
  sqlite> select load_extension('c:\Bin\natsort');
  load_extension('c:\Bin\natsort')

  sqlite>
```
This fix should have no performance impact except on Windows where it is extremely minimal in time and code size.