Interested in improving this site? Please check the To Do page.

Back to SQLite Verbs

Syntax

sqlite.getLastInsertRowId ( databaseId )

Params

databaseId is a number, the database connection ID.

Action

Gets the row id of the last INSERT statement for database connection ID.

Returns

row id, a number.

Examples

bundle {
	local ( databaseId, f, i, query, queryId, record, result );
	
	on getField ( fieldNumber ) {
		local ( s );
		
		s = string.nthField ( record, ',', fieldNumber );
		s = string.delete ( s, 1, 1 );
		s = string.delete ( s, string.length ( s ), 1 );
		
		return ( s )};
	
	bundle { // f
		local ( s );
		
		case sys.os ( ) {
			"MacOS" {
				s = "Temporary Items"};
			"Win95" {
				s = "Temp"}};
		
		f = file.getSpecialFolderPath ( "", s, false ) + "states.db3"};
	
	databaseId = sqlite.open ( f );
	
	for i = 2 to string.countFields ( sqlite.data.statesCsv, '\n' ) {
		record = string.nthField ( sqlite.data.statesCsv, '\n', i );
		record = string.trimWhiteSpace ( record );
		
		query = "INSERT into States ( State, Date_of_statehood, Capital, Capital_since, `Most_populous_city?`, Population, Notes_on_current_capital ) VALUES ( '" + getField ( 1 ) + "', '" + getField ( 2 ) + "', '" + getField ( 3 ) +  "', '" + getField ( 4 ) + "', '" + getField ( 5 ) +  "', '" + getField ( 6 ) + "', '" + getField ( 7 ) + "' )";
		
		queryId = sqlite.compileQuery ( databaseId, query );
		
		result = sqlite.stepQuery ( queryId );
		
		result = sqlite.getLastInsertRowId ( databaseId );
		
		result = sqlite.clearQuery ( queryId )};
	
	sqlite.close ( databaseId )}

Notes

See Also

See Also SQLite APIs


Personal Tools