public
Last active

  • Download Gist
gistfile1.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
//
// CHXMainDatabase.m
// Chocolat
//
// Created by Alex Gordon on 07/03/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
 
#import "CHXMainDatabase.h"
#import "FMDatabase.h"
 
@implementation CHXMainDatabase
 
@synthesize projectName;
@synthesize dirPath;
 
- (NSArray *)tables
{
return [NSArray arrayWithObjects:@"resources", @"passes", @"symbols", nil];
}
- (NSArray *)migrations
{
NSMutableDictionary *baseMigration = [NSMutableDictionary dictionary];
[baseMigration setValue:[NSNumber numberWithInteger:0] forKey:@"version"];
[baseMigration setValue:@"baseMigration" forKey:@"selector"];
return [NSArray arrayWithObjects:baseMigration, nil];
}
- (void)willLoad
{
// This will not corrupt the database if Diglett crashes, but it might if the OS crashes or loses power
[self.db executeUpdate:@"PRAGMA synchronous = OFF"];
[self.db executeUpdate:@"PRAGMA auto_vacuum = INCREMENTAL"];
}
- (void)baseMigration
{
[self.db executeUpdate:
@"CREATE TABLE resources (id INTEGER PRIMARY KEY AUTOINCREMENT, "
@" name TEXT," // The name of the file, including extension
@" path TEXT," // A full path to the file
@" language TEXT," // A full identifier for the base language this file has been detected as
@" is_ignored INTEGER" // Was it decided that this resource should be ignored?
@")"];
[self.db executeUpdate:
@"CREATE INDEX resources_index ON resources (path COLLATE NOCASE)"];
//[self.db executeUpdate:
// @"CREATE INDEX resources_index ON resources (path COLLATE BINARY)"];
[self.db executeUpdate:
@"CREATE TABLE passes (id INTEGER PRIMARY KEY AUTOINCREMENT, "
@" resource INTEGER REFERENCES resources(id) ON DELETE CASCADE," // id of the parent resource row
@" timestamp REAL," // An NSDate timestamp for when this pass was started
@" generator_type TEXT," // The type of the generator, for example "index"
@" generator_name TEXT" //The name of the generator, for example "ctags"
@")"];
[self.db executeUpdate:
@"CREATE INDEX passes_index ON passes (resource)"];
[self.db executeUpdate:
@"CREATE TABLE symbols (id INTEGER PRIMARY KEY AUTOINCREMENT,"
@" pass INTEGER REFERENCES passes(id) ON DELETE CASCADE," // id of the parent pass row
@" name TEXT," // The symbol's identifier
@" qualified_name TEXT," // A qualified name like std::string::find. This is option --extra=+q in ctags
@" regex TEXT," // A regex used to locate the symbol (ctags only)
@" type_code TEXT," // A standardized type code used to identify the symbol
@" parent_id INTEGER," // id of the parent symbol's row in this table
@" parent_name TEXT," // name of the parent symbol
@" parent_type_code TEXT," // the standardized type code of the parent symbol
@" range_line INTEGER," // 0-based line index
@" range_column INTEGER," // 0-based column index
@" range_length INTEGER," // length of the symbol
@" UNIQUE (pass, range_line) ON CONFLICT REPLACE"
@")"];
[self.db executeUpdate:
@"CREATE INDEX symbols_index ON symbols (name COLLATE NOCASE, type_code)"];
[self.db executeUpdate:
@"CREATE INDEX symbols_index ON symbols (range_line, pass)"];
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.