firebase::database

Namespace for the Firebase RealtimeDatabase C++ SDK.

Summary

Enumerations

Error{
  kErrorNone = 0,
  kErrorDisconnected,
  kErrorExpiredToken,
  kErrorInvalidToken,
  kErrorMaxRetries,
  kErrorNetworkError,
  kErrorOperationFailed,
  kErrorOverriddenBySet,
  kErrorPermissionDenied,
  kErrorUnavailable,
  kErrorUnknownError,
  kErrorWriteCanceled,
  kErrorInvalidVariantType,
  kErrorConflictingOperationInProgress,
  kErrorTransactionAbortedByUser
}
enum
Error code returned by Firebase RealtimeDatabase C++ functions.
TransactionResult{
  kTransactionResultSuccess,
  kTransactionResultAbort
}
enum
Specifies whether the transaction succeeded or not.

Typedefs

DoTransaction)(MutableData *data)typedef
Your own transaction handler, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.
DoTransactionFunctiontypedef
std::function<TransactionResult(MutableData *data)>
Your own transaction handler function or lambda, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.
DoTransactionWithContext)(MutableData *data, void *context)typedef
Your own transaction handler, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

Functions

GetErrorMessage(Error error)
const char *
Get the human-readable error message corresponding to an error code.
ServerTimestamp()
constVariant &
Get a server-populated value corresponding to the current timestamp.
operator==(constQuery & lhs, constQuery & rhs)
bool
Compares twoQuery instances.
operator==(constDatabaseReference & lhs, constDatabaseReference & rhs)
bool
Compares twoDatabaseReference instances.

Classes

firebase::database::ChildListener

Child listener interface.

firebase::database::DataSnapshot

ADataSnapshot instance contains data from a FirebaseDatabase location.

firebase::database::Database

Entry point for the Firebase RealtimeDatabase C++ SDK.

firebase::database::DatabaseReference

DatabaseReference represents a particular location in yourDatabase and can be used for reading or writing data to thatDatabase location.

firebase::database::DisconnectionHandler

Allows you to register server-side actions to occur when the client disconnects.

firebase::database::MutableData

Instances of this class encapsulate the data and priority at a location.

firebase::database::Query

TheQuery class is used for reading data.

firebase::database::ValueListener

Value listener interface.

Enumerations

Error

Error

Error code returned by Firebase RealtimeDatabase C++ functions.

Properties
kErrorConflictingOperationInProgress

An operation that conflicts with this one is already in progress.

For example, calling SetValue and SetValueAndPriority on aDatabaseReference is not allowed.

kErrorDisconnected

The operation had to be aborted due to a network disconnect.

kErrorExpiredToken

The supplied auth token has expired.

kErrorInvalidToken

The specified authentication token is invalid.

kErrorInvalidVariantType

You specified an invalidVariant type for a field.

For example, aDatabaseReference's Priority and the keys of a Map must be of scalar type (MutableString, StaticString, Int64, Double).

kErrorMaxRetries

The transaction had too many retries.

kErrorNetworkError

The operation could not be performed due to a network error.

kErrorNone

The operation was a success, no error occurred.

kErrorOperationFailed

The server indicated that this operation failed.

kErrorOverriddenBySet

The transaction was overridden by a subsequent set.

kErrorPermissionDenied

This client does not have permission to perform this operation.

kErrorTransactionAbortedByUser

The transaction was aborted, because the user's DoTransaction function returned kTransactionResultAbort instead of kTransactionResultSuccess.

kErrorUnavailable

The service is unavailable.

kErrorUnknownError

An unknown error occurred.

kErrorWriteCanceled

The write was canceled locally.

TransactionResult

TransactionResult

Specifies whether the transaction succeeded or not.

Properties
kTransactionResultAbort

The transaction did not succeed.

Any changes to theMutableData will be discarded.

kTransactionResultSuccess

The transaction was successful, theMutableData was updated.

Typedefs

DoTransaction

TransactionResult(*DoTransaction)(MutableData*data)

Your own transaction handler, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

Note: This version of the callback is no longer supported (unless you are building for Android with stlport). You should use either one of DoTransactionWithContext (a simple function pointer that accepts context data) or DoTransactionFunction (based on std::function).See also:DoTransactionWithContext for more information.

DoTransactionFunction

std::function<TransactionResult(MutableData*data)>DoTransactionFunction

Your own transaction handler function or lambda, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

See also:DoTransactionWithContext for more information.

DoTransactionWithContext

TransactionResult(*DoTransactionWithContext)(MutableData*data,void*context)

Your own transaction handler, which the Firebase RealtimeDatabase library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

The context you specified to RunTransaction will be passed into this call.

This function will be called,possibly multiple times, with the current data at this location. The function is responsible for inspecting that data and modifying it as desired, then returning a TransactionResult specifying either that theMutableData was modified to a desired new state, or that the transaction should be aborted. Whenever this function is called, theMutableData passed in must be modified from scratch.

Since this function may be called repeatedly for the same transaction, be extremely careful of any side effects that may be triggered by this function. In addition, this function is called from within the Firebase RealtimeDatabase library's run loop, so care is also required when accessing data that may be in use by other threads in your application.

Best practices for this function are to ONLY rely on the data passed in.

Note: If you want a callback to be triggered when the transaction is finished, you can use the Future value returned by the method running the transaction, and callFuture::OnCompletion() to register a callback to be called when the transaction either succeeds or fails.See also:DoTransaction for more information.

Details
Parameters
data
Mutable data, which the callback can edit.
context
Context pointer, passed verbatim to the callback.
Returns
The callback should return kTransactionResultSuccess if the data was modified, or kTransactionResultAbort if it was unable to modify the data. If the callback returns kTransactionResultAbort, the RunTransaction() call will return the kErrorTransactionAbortedByUser error code.

Functions

GetErrorMessage

constchar*GetErrorMessage(Errorerror)

Get the human-readable error message corresponding to an error code.

Details
Parameters
error
Error code to get the error message for.
Returns
Statically-allocated string describing the error.

ServerTimestamp

constVariant&ServerTimestamp()

Get a server-populated value corresponding to the current timestamp.

When inserting values into the database, you can use the special valuefirebase::database::ServerTimestamp() to have the server auto-populate the current timestamp, which is represented as millieconds since the Unix epoch, into the field.

Details
Returns
A special value that tells the server to use the current timestamp.

operator==

booloperator==(constQuery&lhs,constQuery&rhs)

Compares twoQuery instances.

TwoQuery instances on the same database, in the same location, with the same parameters (OrderBy*, StartAt, EndAt, EqualTo, Limit*) are considered equivalent.

Equivalent Queries have a shared pool of ValueListeners and ChildListeners. When listeners are added or removed from oneQuery instance, it affects all equivalentQuery instances.

Details
Parameters
lhs
TheQuery to compare against.
rhs
TheQuery to compare against.
Returns
True if theQuery instances have the same database, the same path, and the same parameters, determined by StartAt(), EndAt(), EqualTo(), and the OrderBy and LimitTo methods. False otherwise.

operator==

booloperator==(constDatabaseReference&lhs,constDatabaseReference&rhs)

Compares twoDatabaseReference instances.

Details
Parameters
lhs
rhs
ADatabaseReference to compare against.
Returns
True if theDatabaseReference instances have the same URL. False otherwise.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-18 UTC.