Detecting if database is already encrypted

Have asked ChatGPT how I can check if database is already encrypted. He explained to perform following code (iOS)

sqlite3_key(db, key, Int32(key.count))

// Try a query to determine if the database is already encrypted
if sqlite3_exec(db, “SELECT count(*) FROM sqlite_master;”, nil, nil, nil) != SQLITE_OK
{
// database is not crypted… encrypt it
// …
}

I have done some tests with an unencrypted db, and encrypted db, and it seems to be OK.
Could you confirm this is valid? I searched in this forum, and read that we should do some complicated things like checking some headers…