Пример #1
0
void testAppend(){
	
	OsFile id;/* I don't like the implementation since OSFile need to create by myself*/
	int Readonly;

	int i,nPages;
	double time;
	
	char * buf=sqlite3Malloc(config.pagesize);
	rc = sqlite3OsOpenReadWrite( config.datfile, &id, &Readonly);
	errorHandle(rc, "can't open the file");

	for(nPages=1; nPages<=config.pagenum; nPages++){
		
		printf("append %d pages!\n",nPages);
		
		
		start_timer();
		for(i=0;i<nPages;i++){
			sqlite3Randomness(config.pagesize, buf);
			rc = sqlite3OsWrite(&id, buf, config.pagesize);
			errorHandle(rc, "write error");
		}
		time = get_timer();
		pr_times(config.recordfile, time);
				

	}
	rc= sqlite3OsClose(&id);
	errorHandle(rc, "can't close the file");

    //TODO can't find the defintion, do it later
    //sqlite3Free((void *)buf);
}
Пример #2
0
/*
** Usage:   fake_big_file  N  FILENAME
**
** Write a few bytes at the N megabyte point of FILENAME.  This will
** create a large file.  If the file was a valid SQLite database, then
** the next time the database is opened, SQLite will begin allocating
** new pages after N.  If N is 2096 or bigger, this will test the
** ability of SQLite to write to large files.
*/
static int fake_big_file(
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  int argc,              /* Number of arguments */
  const char **argv      /* Text of each argument */
){
  int rc;
  int n;
  i64 offset;
  OsFile *fd = 0;
  int readOnly = 0;
  if( argc!=3 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
       " N-MEGABYTES FILE\"", 0);
    return TCL_ERROR;
  }
  if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
  rc = sqlite3OsOpenReadWrite(argv[2], &fd, &readOnly);
  if( rc ){
    Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
    return TCL_ERROR;
  }
  offset = n;
  offset *= 1024*1024;
  rc = sqlite3OsSeek(fd, offset);
  if( rc ){
    Tcl_AppendResult(interp, "seek failed: ", errorName(rc), 0);
    return TCL_ERROR;
  }
  rc = sqlite3OsWrite(fd, "Hello, World!", 14);
  sqlite3OsClose(&fd);
  if( rc ){
    Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
    return TCL_ERROR;
  }
  return TCL_OK;
}