GSI


sqlite3 의 쿼리중에서 select 에서 랜덤하게 뿌리는게 없는줄 알았다. ㅋ.

select * from s1 order by random()

이 쿼리를 사용하면 랜덤하게 출력할 수 있다.
Posted by gsi
:



VC++ 2008을 작업 하다 보면 다른 pc에서 이런 오류 메시지를 종종 보게 된다.
이때 해결 방법은 몇가지로 나눠 진다.

1. DLL을 같이 배포
  - C:\Program Files\Microsoft Visual Studio 9.0\VC\redist 폴더 안에 있는 debug, release 의 내용을 복사해서 같이 배포 한다.
  - 사실 이렇게 해봤지만. 되지 않을때가 많다.

2. 배포 패키지를 사용
  - 어떤 개발툴(2005, 2008) 둘중에 하나를 쓰게 되는데요. 이때 선택해서 배포 패키지를 깔아서 써야 한다.




  - 위의 3개 중에서 내가 테스트 할때는 2008로 개발했을때인데.. 이때 sp1 빼고 2008 배포 패키지만 깔아도 될때도 있었다.

Tip :
  - 컴파일 할때 보면 "다중 스레드 디버그 DLL", "다중 스레드 디버그" 두개가 실행파일의 dll 관계를 보면 좀 틀려 보이긴 한다. 어쩔땐 이걸 해결하면 될때도 있다.. 쩝.. 너무 귀찮다.

[아래 화면은 Tip에 적어 놓은, 걸 Depends로 찍어 본것..]
Posted by gsi
:

s1.sqlitedb 를 하나 제작했습니다.

그리고 나서 xcode의 resource에 추가를 했습니다.
그리고 아래와 같은 코드를 이용해서 프로그램을 짜주었습니다.

-(void) readAnimalsFromDatabase {

// Setup the database object

sqlite3 *database;

// Init the animals Array

// animals = [[NSMutableArray alloc] init];

// Open the database from the users filessytem

if(sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK) {

// Setup the SQL Statement and compile it for faster access

NSString* sqlStatement = [NSString stringWithFormat:@"select * from s1"];

sqlite3_stmt *compiledStatement;

if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {

// Loop through the results and add them to the feeds array

while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

int idx = sqlite3_column_int( compiledStatement, 0 );

int level = sqlite3_column_int( compiledStatement, 1 );

int c1 = sqlite3_column_int( compiledStatement, 2 );

int c2 = sqlite3_column_int( compiledStatement, 3 );

int c3 = sqlite3_column_int( compiledStatement, 4 );

// Create a new animal object with the data from the database

// Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];

// Add the animal object to the animals Array

// [animals addObject:animal];

// [animal release];

}

}

else

{

NSString* msg = [[NSString alloc] initWithFormat:@"%s", sqlite3_errmsg( database )];

NSLog( @"Failed to open database with message '%s'.", sqlite3_errmsg( database ) );

}

// Release the compiled statement from memory

sqlite3_finalize(compiledStatement);

}

sqlite3_close(database);

}

** 연동 방법에 대해서는 따로 적지를 않았습니다.


이렇게 작업 후에 테스트를 해보니 이상한 결과가 나오더군요.

if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement,NULL) == SQLITE_OK)

여기 코드에서 "실패"가 떨어 지더라구요.
그래서 위의 코드에서 보는 msg라는 내용에 글자를 찍어 보면

no such table s1 이라고 나오게 됩니다.

그래서 과연 이 파일이 어디 있나 찾아 봤더니 컴파일 되고 빌드 되면서
해당 응용 프로그램의 document에 하나 생기더군요 하지만 사이즈가 0으로 나오더라구요.

그래서 다른 소스들을 보니 아래의 메소드를 적용해주는걸 보았습니다.

-(void) checkAndCreateDatabase{

// Check if the SQL database has already been saved to the users phone, if not then copy it over

BOOL success;

// Create a FileManager object, we will use this to check the status

// of the database and to copy it over if required

NSFileManager *fileManager = [NSFileManager defaultManager];

// Check if the database has already been created in the users filesystem

success = [fileManager fileExistsAtPath:[self dataFilePath]];

// If the database already exists then return without doing anything

if(success) return;

// If not then proceed to copy the database from the application to the users filesystem

// Get the path to the database in the application package

NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kFilename];

// Copy the database from the package to the users filesystem

[fileManager copyItemAtPath:databasePathFromApp toPath:[self dataFilePath] error:nil];

[fileManager release];

}


위의 코드를 수행하게 되면 document에 데이터가 없다면 복사를 수행하라는 의미의 코드인듯 합니다.( 사실 이 부분은 아직 잘 모름 )


그래서 위의 함수를 적용 및 호출을 아래와 같이 해주니까.

제대로 데이터가 불러와 지더군요.


- (id) init

{

if (self = [super init])

{

touchPos = CGPointMake(0, 0);

gameState = kLogo;

logoBack = [[LogoBack alloc] init];

// Execute the "checkAndCreateDatabase" function

[self checkAndCreateDatabase];

// Query the database for all animal records and construct the "animals" array

[self readAnimalsFromDatabase];

}

return self;

}


위의 내용에 대해서 실제적인 코드는 여기 압축을 해서 올리지 못하지만,

sqlite3의 내용을 조금 숙지 하셨다면 금방 이해 하시리라 믿습니다. ^^


이거 가지고 조금 삽질을 했네요.

다행이 이 코드를 보면서 다른 면을 보게 되서 더 기쁘네요 ^^

Posted by gsi
:


기본 DB를 만들면 sqlite는 idx등의 고유번호를 자동증가가 안되는거 같다.

그래서 아래와 같이 Execute SQL에서 아래와 같은 쿼리를 통해서
값을 처리 해야 한다.


위와 같이 쿼리를 해서 "Exeture Query" 를 누른다.

위와 같이 s1 이란 것과 "sqlite_sequence" 가 생기게 된다.

Posted by gsi
:

Texture2DEx2.h
-------------------------------

#import <Foundation/Foundation.h>

#import "Texture2D.h"


@interface Texture2DEx2 : Texture2D {

CGPoint tileSize;

CGPoint frameSize;

int curIndex;

int Delay;

int Tick;

}


@property CGPoint tileSize;

@property CGPoint frameSize;

@property int curIndex;

@property int Delay;

@property int Tick;


- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay;

- (void) drawAtPointTest:(CGPoint)point;


@end



Texture2DEx2.m
-------------------------------

#import "Texture2DEx2.h"



@implementation Texture2DEx2


@synthesize tileSize;

@synthesize frameSize;

@synthesize curIndex;

@synthesize Delay;

@synthesize Tick;


- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay

{

self.tileSize = ts;

self.frameSize = fs;

self.Delay = delay;

self.Tick = 0;

}


- (void) drawAtPointTest:(CGPoint)point 

{

if( Tick > Delay )

{

Tick = 0;

curIndex++;

if( curIndex >= frameSize.x )

{

curIndex = 0;

}

}

Tick++;

GLfloat leftTc = tileSize.x * curIndex / _width;

GLfloat rightTc = tileSize.x * (curIndex+1) / _width;

GLfloat coordinates[] = { leftTc, _maxT,

rightTc, _maxT,

leftTc, 0,

rightTc, 0 };

// 넓이와 높이는 타일의 사이즈로 교체

GLfloat width = tileSize.x,

height = tileSize.y;

GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,

width / 2 + point.x, -height / 2 + point.y, 0.0,

-width / 2 + point.x, height / 2 + point.y, 0.0,

width / 2 + point.x, height / 2 + point.y, 0.0 };

glBindTexture(GL_TEXTURE_2D, _name);

glVertexPointer(3, GL_FLOAT, 0, vertices);

glTexCoordPointer(2, GL_FLOAT, 0, coordinates);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

}


@end


/////////////////

Texture2DEx2 *bluePlaneEx;


@property (nonatomic, retain) Texture2DEx2 *bluePlaneEx;



if (bluePlaneEx == nil) {

self.bluePlaneEx = [[Texture2DEx2 alloc] initWithImage: [UIImage imageNamed:@"bluePlane2.png"]];

glBindTexture(GL_TEXTURE_2D, sprite.name);

// 타일 사이즈, 이미지 내부 프레임 개수, 딜레이 타임(호출타임)

[self.bluePlaneEx TileSize:CGPointMake(63.0, 55.0) FrameSize:CGPointMake(3, 1) Delay:10];

[bluePlaneEx drawAtPointTest:CGPointMake(Pos.x, Pos.y)];



Posted by gsi
: